Using the last-child selector(使用最后一个子选择器)
问题描述
我的目标是在最后一个 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.
这篇关于使用最后一个子选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用最后一个子选择器
基础教程推荐
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
