我有一个菜单列表。我没有使用 UL/LI,只是嵌套的 DIV。菜单项之间有图形分隔符。列表中的第一项需要抑制左填充;最后一项需要抑制正确的填充和图形分隔符。这是 CSS:
.platformItem {
float: left;
padding: 0 12px;
background: url(/includes/themes/02RWO/images/assets/separator.gif) no-repeat top right;
}
.platformItem .first {
padding-left: 0 !important;
}
.platformItem .last {
padding-right: 0 !important;
background-image: none !important;
}
这是 HTML:
<div id="platformMenu">
<div class="platformItem first"><a href="">All</a></div>
<div class="platformItem"><a href="">Windows</a></div>
<div class="platformItem"><a href="">Mac</a></div>
<div class="platformItem"><a href="">Linux</a></div>
<div class="platformItem last"><a href="">Web</a></div>
<div class="Clear"></div>
</div>
我希望我可以使用修饰符 类来抑制某些属性。这可能吗?有更好的方法吗?
谢谢。
最佳答案
您可以使用 first-child现代浏览器中的伪选择器。 last-child isn't supported in IE7 or IE8 , 尽管。你也可以看看jQuery's enhanced selectors :
$(文档).ready(函数(){
$("div span:last-child")
.css({color:"red", fontSize:"80%"})
});
关于CSS:取消列表开头和结尾的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1167837/