css3 last-child 语法不起作用

标签 css css-selectors

我无法让 last-child 伪类影响最后一个列表项。我的 css 语法有什么错误?网址 = http://chesstao.com

我无法让 last-child 伪元素影响最后一个列表项。我的 css 语法有什么错误?

 HTML:
 <section class="top-bar-section">

 <ul class="right"> 

 <li class="has-dropdown">
 <a href="#">instruction</a>
 <ul class="dropdown">
 <li><a class="plain" href="#">Students</a></li>

 <li><a href="#">Products</a></li>
 <li><a href="#">Services</a></li>
 <li><a href="#">my rates</a></li>

 </ul>
 </li>

 </ul>

 CSS3:

 .top-bar-section ul li.has-dropdown ul.dropdown:last-child {background:red !important;}

最佳答案

首先你缺少一个</li>结束标记

<li>
    <a class="plain has-dropdown" href="products.php" >Products</a>
</li>

它是

ul.dropdown li:last-child {background:red;}

而且你不需要!important

演示:http://jsfiddle.net/fsFLy/1/

关于css3 last-child 语法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21806748/

相关文章:

html - 在导航容器内居中导航元素

多个元素的 CSS 选择器

css - :first-child not being applied

css - 在 CSS 中使用非常具体的选择器有优势吗?

html - 悬停 <a> 元素时显示相邻的 div?

css - 我可以只将 Twitter-Bootstrap 样式添加到原始 GWT 组件吗

css - 在 SASS 中,如何在创建选择器时避免插值前的空格?

css - 是否有 CSS 父级选择器?

jquery - 选择并更改具有特定值的 css ("color") 的所有元素的属性

html - 从背景中切割出像素线的文本