html - :Last-Child not working with Nav Bar?

标签 html css

<div id="header"><!--start #header-->
    <img id="logo" height="80" src="../resources/CHUG-LOGO.png" />
    <ul>
        <a href="../home" title="Home"><li id="home"><h2>Home</h2></li></a>
        <a href="../about" title="About"><li id="about"><h2>About</h2></li></a>
        <a href="../store" title="Store"><li id="store"><h2>Store</h2></li></a>
        <a href="../contact" title="Contact"><li id="contact"><h2>Contact</h2></li></a>
    </ul>                    
</div><!--end #header-->
#header ul {
    padding: 0px;
    list-style-type: none;
    margin: 0px;
    float: right;
}
#header ul li {
    text-align: center;
    display: block;
    margin: 0px;
    float: left;
    padding-top: 45px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    height: 65px;
    border-left: 1px solid #755b2c;
    border-right: 1px solid #b99e68;
}
#header ul li h2 {
    min-width: 105px;
    margin: 0px;
    padding: 0px;
    display: inline-block;
    color: #000;
    font-size: 20px;
    font-weight: bold;
}

这是我的导航栏代码,我试图删除最后一个列表项的右边框。我知道我需要使用伪标识符 :last-child,但我似乎无法让它工作。有什么想法吗?

最佳答案

li 在技术上不是 ul 元素的子元素,因为它们被 a 元素包裹。将 a 移动到 li 的内部并再次使用相同的代码。

关于html - :Last-Child not working with Nav Bar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13907119/

相关文章:

javascript - 1 个 html 页面上的 2 个不同的谷歌图表(1 个带有 JSON 和 3x 仪表硬编码的折线图)

jquery - .slideToggle 表现不正常?

javascript - 如何使用 Jquery 重置单个 div

css - 两个div并排,右侧div固定宽度

javascript - 如何在html5或javascript中发出RTSP请求?

css - 如何访问 <a href 标签内的 <img 标签以在 IE 中将焦点设置为 <img

html - div 在屏幕上高于父 div 时被截断

html - 下拉子菜单显示不正确

html - 如何使用 struts1.3 Action 生成动态组合框并在页面提交时也获取其值?

javascript - 具有 history.pushState 和 popstate 的 Ajax - 当 popstate 状态属性为 null 时我该怎么办?