在我的菜单中添加边框颜色

时间:2015-09-15 20:25:16

标签: html css

我尝试在菜单上创建一个效果。

我尝试在菜单中的每个“li”顶部添加一个3px边框。我希望它的边框出现在悬停状态。但我没有成功。

我尝试:之后但没有任何改变。

#mm {
    width: 960px;
    height: 50px;
    background-color: #e8e4e0;
}

#mm ul li {
    display: inline-block;
    width: 160px;
    height: 50px;
}

#mm ul li a {
    text-transform: uppercase;
    color: #372f7e;
    font-size: 9.2px;
    line-height: 50px;
    text-align: center;
}

#mm ul li:hover {
    content: '';
    position: relative;
    background-color: #ffffff;
    font-weight: bold;
    border-top: 4px solid black;
    line-height: 46px;
}


<div id="mm">
            <ul>
                <li><a href="">Choice</a></li>
                <li><a href="">Choice</a></li>
                <li><a href="">Choice</a></li>
                <li><a href="">Choice</a></li>
                <li><a href="">Choice</a></li>
                <li><a href="">Choice</a></li>
            </ul>
        </div>

1 个答案:

答案 0 :(得分:1)

我认为你的代码几乎没问题。它有效,但看起来很糟糕。最好让border-top具有透明色,然后在悬停时更改它:

#mm ul li {
    border-top: 4px solid transparent;
}

#mm ul li:hover {
    border-top-color: black;
}

以下是示例http://jsfiddle.net/infous/abmhtL4x/