You should use border-topinstead overline, with some padding-top, to fill the gap between the line and the top line.
, border-top: 4px solid transparent;, transparent border, , , :hover , CSS Box Box Model counts border , , .
HTML
<ul>
<li><a href="#">Hello</a></li>
<li><a href="#">World</a></li>
</ul>
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 5px;
margin-right: 10px;
border-top: 4px solid transparent;
}
ul li:hover {
border-top: 4px solid #f00;
}
width :before :after, HTML , .
2
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 8px;
margin-right: 10px;
position: relative;
}
ul li:after {
position: absolute;
width: 90%;
content: "";
top: 0;
left: 50%;
margin-left: -45%;
}
ul li:hover:after {
border-top: 4px solid #f00;
}