我试图简化CSS,却无法理解为什么不能将样式应用于同一类的不同元素类型。
例如,下面仅将所有.forum元素设置为海军风格,而其他更具体的样式将被忽略。有没有解决的办法?
的HTML
<h1 class="forum">Forum Header</h1>
<p class="forum">Forum Content</p>
<small class="forum">Small deets</small>
的CSS
.forum {
color: navy;
}
.forum h1 {
text-decoration: underline;
}
.forum small {
font-size: 2em;
}
试试这个:
.forum {
color: navy;
}
h1.forum {
text-decoration: underline;
}
small.forum {
font-size: 2em;
}
请注意,您使用了错误的选择器,这.forum h1
意味着选择h1
which是.forum
while的后代,这h1.forum
意味着选择h1
具有class的元素forum
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句