html - 下拉菜单边框未扩展到全宽

标签 html css

我正在尝试为下拉菜单选项卡创建底部边框。我知道在哪里添加属性来添加边框,但我遇到的问题是边框没有一直从左到右延伸。

HTML:

<div id="navigation">
    <ul>
        <li><a href="#" id="home">Home</a></li>
        <li><a href="#" id="zeus">Zeus</a>
        <li><a href="#" id="poseidon">Poseidon</a>
        <li><a href="#" id="hercules">Hercules</a>
        <li><a href="#" id="athena">Athena</a>
        <li><a href="#" id="help">Help</a>
            <ul>
                <li><a href="#">Contact</a></li>
                <li><a href="#">FAQ's</a></li>
            </ul>
        </li>
        <li><a href="#" id="account">Account</a>
            <ul>
                <li><a href="#">Cart</a></li>
                <li><a href="#">Orders</a></li>
            </ul>
        </li>
    </ul>
</div>

CSS:

#navigation {
    background-color: #404040;
    display: block;
    text-align: center;
}

#navigation ul {
    display: block;
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: relative;
}

#navigation ul a {
    color: white;
    display: block;
    font-size: 18px;
    font-weight: 500;
    line-height: 32px;
    padding: 0 30px;
    text-decoration: none;
}

#navigation ul li {
    display: inline-block;
    margin: 0;
    padding: 0;
    position: relative;
}

#navigation ul ul {
    display:none;
    position:absolute;
    top:100%;
    left:0;
    background:#fff;
    padding:0
}

#navigation ul ul a {
    line-height: 120%;
    padding: 10px 15px;
}

#home:hover {
    color: gray;
}

#zeus:hover {
    color: red;
}

#poseidon:hover {
    color: blue;
}

#hercules:hover {
    color: gold;
}

#athena:hover {
    color: #00ff00;
}

#help:hover {
    color: gray;
}

#account:hover {
    color: gray;
}

#navigation ul li ul a:hover {
    color: gray;
}

#navigation ul li:hover > ul {
    display: block;
    background-color: #404040; 
    text-align: left;
    z-index: 99;
}

最佳答案

您已将 li 设置为 display:inline-block,这使其根据内容“缩小以适合”。您可以将 width:100 添加到子级 li 以确保它始终保持父级的全宽。

#navigation li li {
  border-bottom: 1px solid lime;
  width: 100%;
}

jsFiddle

关于html - 下拉菜单边框未扩展到全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35211891/

相关文章:

html - 对齐 HTML 列表

html - 如何使html数据列表溢出?

css - IE8 忽略 td 宽度,适用于 IE7

html - 具有可变内容和窗口宽度的 CSS 左浮动

html - 在 HTML 和 CSS 中显示与菜单项内联的 Logo

javascript - 如果 textarea 中有新行,则添加 1 行并增加 textarea 的大小

Javascript 点击元素

jquery - 如何只向下滑动当前元素

html - 当我将鼠标悬停在按钮上时,我想要新图像来描述该按钮,但它在闪烁

html - 水平站点宽度超过 4000 像素的 Css3 动画问题