考虑以下 html:
<div id="rightBar">
<div class="barElement">
<div class="barText"><a href="#">Not underlined</a><br /></div>
<div class="barLinks"><a href="#">Should be underlined</a></div>
</div>
</div>
以及以下 CSS:
#rightBar a
{
text-decoration: none;
}
#rightBar a.barLinks
{
text-decoration: underline;
}
'Should be underlined' 链接没有带下划线,不应该是因为它继承了类 barLinks 和 id rightbar。此外,'#rightBar a.barLinks' (0, 1, 1, 1) 比 '#rightBar a' (0, 1, 0, 1) 具有更高的特异性,因此它应该覆盖后者,对吗?
在不使用任何内联规范(css 或 html)的情况下,我还能如何让“应该加下划线”链接加下划线
最佳答案
您的 a
元素没有类 barLinks
。这样做:
#rightBar .barLinks a
{
text-decoration: underline;
}
关于CSS 和特异性 - 类 vs id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6550296/