如何使用:在CSS中不是选择器? [英] How to use :not selector in CSS?

查看:167
本文介绍了如何使用:在CSS中不是选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题说的一切。我是CSS新的。我试图使用以下代码,但它不工作:

My question says everything. I am new in CSS. I am trying to use following code but it is not working:

ul.verticalNav {
    /*declaration*/
}

ul.verticalNav li {
    /*declaration*/
}

ul.verticalNav li a {
    /*declaration*/
}

ul.verticalNav li a:not(:nth-last-child(1)) {
    border-bottom: 1px solid #323232;
}

ul.verticalNav li a:not :nth-​​last-child(1))不创建边框。 HTML是:

The class ul.verticalNav li a:not(:nth-last-child(1)) is not creating borders. The HTML is:

<ul class="verticalNav">
    <li><a href="#">Home</a></li>
    <li><a href="#">View Profile</a></li>
    <li><a href="#">Edit Profile</a></li>
    <li class="bottomLeftMenuItem"><a class="bottomLeftMenuItem" href="#">Search Profile</a></li>
</ul>

我无法找到问题。

提前感谢。

我使用的是Firefox 12.0和Google Chrome 18.0.1025.168 m。

I am using Firefox 12.0 and Google Chrome 18.0.1025.168 m.

推荐答案

您的选择器不正确,应该是

Your selector is wrong, it should be

ul.verticalNav li:not(:nth-last-child(1)) a {
    border-bottom: 1px solid #323232;
}​

这是因为您的标记,< a> ; 始终是其< li> 父级的最后一个子级。您想要的是将样式应用于< li> 中的< a> 最后一个孩子。

That's because with your markup, <a> is always going to be the last child of its <li> parent. What you want is to apply the style to <a>s inside any <li> which is not a last child.

这篇关于如何使用:在CSS中不是选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆