html - 伪类 :last-child weirdness

标签 html css stylesheet css-selectors

我希望最后一个菜单项是蓝色的,我正在尝试使用伪类 a:last child 来实现这一点。奇怪的是,它将规则应用于菜单中间看似随机的 a:link。你能告诉我为什么吗?

网站: http://www.robert-wright-books.com/STAGE

CSS:

#access {
 background: transparent;
 float: left;
 font-size: 1.4em;
 text-transform: uppercase;
 overflow: hidden;
 width: 238px;
 margin: 36px 0 0 18px;
}
#access a:last-child {  color: #006ccf }
#access ul {
 list-style-type: none;
 margin: 0;
 padding: 0;
 margin-bottom: 0;
}
#access ul li { border-bottom: 1px dotted #957e5e }
#access ul li:last-child { border-bottom: none }
#access ul li a,
#access ul li a:hover,
#access ul li a:visited {
 color: #432f00;
 display: block;
 padding: 6px 24px;
 line-height: 17px;
 text-decoration: none;
}

最佳答案

考虑到 #access a#access 的唯一 a 子级, 其余链接都包含在 LI 中,因此 LI 是 child ,而不是 A

#access ul li:last-child a 指向最后一个菜单项。

关于html - 伪类 :last-child weirdness,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5628023/

相关文章:

html - 使用 css 创建钻石叠加图像

html - 问题制作被阻止的 div

javascript - 全高嵌入 PDF

javascript - 如何用我当前的代码切换标志?

javascript - html 5 计数器的 drop 功能

asp.net - 使用 CSS 将一个 div 放在另一个 div 之上

html - 将第三个水平 div 定位到其他 div 的底部?

css - 如何在 GWTP 中正确使用 CSS?

html - CSS,为什么地址是 "nav a"而不是 "li"?

html - 这是设置媒体查询的有效且正确的方法吗?