【发布时间】:2016-12-03 15:19:14
【问题描述】:
我正在尝试使用 CSS。
这是我的代码http://codepen.io/anon/pen/mJxrdE
这是html
<html>
<head>
<meta charset="UTF-8">
<title>Sample document</title>
<link rel="stylesheet" href="style1.css">
</head>
<body>
<p id="first">
<strong class="carrot">C</strong>ascading
<strong class="spinach">S</strong>tyle
<strong class="spinach">S</strong>heets
</p>
<p id="second">
<strong>C</strong>ascading
<strong>S</strong>tyle
<strong>S</strong>heets
</p>
</body>
</html>
这是 CSS
p {color: blue; }
strong {color : red;text-decoration: underline;}
.carrot {color:orange;}
.spinach {color:green;}
#first {font-style:italic;color:brown;}
#second {color:blue;}
我不明白为什么第一行不是完全棕色的。我认为 id (#first) 比类 (.carrot) 具有更高的优先级。
我尝试从http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/ 计算特异性 .所以 .carrot 有 [0,0,1,0] 而#first 有 [0,1,0,0]。我不确定发生了什么事。
最初,我认为子样式会覆盖父样式,但对此我得到了相互矛盾的答案。
【问题讨论】:
-
.spinach {color:green;} 类应用在 Style 如果你想第一行完全棕色,那么你需要先删除该类形式使用它的行
-
还有 class="carrot" 应用在那里
标签: css