css权重题

<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>第1题</title>
	<style type="text/css">
		#father #son {
			color: blue;
		}

		#father p.c2 {
			color: black;
		}

		div.c1 p.c2 {
			color: red;
		}

		#father {
			color: green !important;
			/* 继承的权重为0 */
		}
	</style>
</head>

<body>
	<div id="father" class="c1">
		<p id="son" class="c2">
			试问这行字体是什么颜色的?
		</p>
	</div>
</body>

</html>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>第2题</title>
		<style type="text/css">
			#father{
				color:red;/* 继承的权重为0 */
			}
			p{
				color:blue;  
			}
		</style>
	</head>
	<body>
		<div id="father">
			<p>试问这行字体是什么颜色的?</p>
		</div>
	</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>第3题</title>
	<style type="text/css">
		div p {
			color: red;
		}

		#father {
			color: red;
		}

		p.c2 {
			color: blue;
		}
	</style>
</head>

<body>
	<div id="father" class="c1">
		<p class="c2">
			试问这行字体是什么颜色的?
		</p>
	</div>
</body>

</html>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>第4题</title>
		<style type="text/css">
			div div{ 
				color:blue;
			}
			div{
				color:red;
			}
		</style>
	</head>
	<body>
		<div>
			<div>
				<div>
					试问这行字体是什么颜色的?
				</div>
			</div>
		</div>
	</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<style type="text/css">
		div div div div div div div div div div div div{  
			color:red;
		}
		.me{ 
			color:blue;
		}
	</style>
</head>
<body>
	<div>
		<div>
			<div>
				<div>
					<div>
						<div>
							<div>
								<div>
									<div>
										<div>
											<div>
												<div class="me">试问这行文字是什么颜色的</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<style type="text/css">
		.c1 .c2 div {
			color: blue;
		}

		/* 权重一样比优先级 */
		div #box3 {
			color: green;
		}

		#box1 div {
			color: yellow;
		}
	</style>
</head>

<body>
	<div id="box1" class="c1">
		<div id="box2" class="c2">
			<div id="box3" class="c3">
				文字
			</div>
		</div>
	</div>
</body>

</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值