【发布时间】:2021-05-14 10:54:34
【问题描述】:
我有一个简单的navbar,我通过ul 有几个菜单项,我想做的是每当我将鼠标悬停在li 上时,border-bottom 就会出现在@ 的center 987654326@ 但我首先遇到一些问题是border-bottom's 宽度离开了文本,有时它没有覆盖上面文本的完整width
body{
margin: 0px;
padding: 0px;
background: #2c3e50;
}
.header__middle ul{
list-style-type: none;
display: flex;
}
.header__middle ul li a{
margin-right: 10px;
text-decoration: none;
font-size: 1.2em;
color: black;
text-align: center;
}
.header__middle ul li {
position: relative;
}
.header__middle ul li:hover ::after{
content: "";
position: absolute;
left: 4%;
bottom: -13%;
width: 40px;
border-bottom: 2px solid black;
}
<div class="header__middle">
<ul>
<li ><a href="#">Home</a></li>
<li><a href="#">Join</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">About Us</a></li>
</ul>
</div>
HTML
【问题讨论】:
标签: html css hover html-lists