使用最后一个子选择器 [英] Using the last-child selector

查看:17
本文介绍了使用最后一个子选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在最后一个 li 上应用 CSS,但它没有这样做.

My goal is to apply the CSS on the last li, but it doesn't do that.

#refundReasonMenu #nav li:last-child {
    border-bottom: 1px solid #b5b5b5;
}

<div id="refundReasonMenu">
    	<ul id="nav">
    		<li><a id="abc" href="#">abcde</a></li>
    		<li><a id="def" href="#">xyz</a></li>
    	</ul>
    </div>

如何只选择最后一个孩子?

推荐答案

:last-child 伪类仍然不能可靠地跨浏览器使用.特别是,Internet Explorer 版本 <9、Safari <3.2 肯定 不支持,虽然 Internet Explorer 7 和 Safari3.2 支持:first-child,奇怪.

The :last-child pseudoclass still cannot be reliably used across browsers. In particular, Internet Explorer versions < 9, and Safari < 3.2 definitely don't support it, although Internet Explorer 7 and Safari 3.2 do support :first-child, curiously.

最好的办法是显式地为该项目添加一个 last-child(或类似的)类,并改为应用 li.last-child.

Your best bet is to explicitly add a last-child (or similar) class to that item, and apply li.last-child instead.

这篇关于使用最后一个子选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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