[英]How do I add a bottom border under contact in my vertical navigation bar using css?
I am learning to code and can't seem to apply a 1px solid border-bottom under contact.我正在学习编码,但似乎无法在接触下应用 1px 实心边框底部。
And if I do, the other bottom borders above become bolder as if they are double bordering.如果我这样做了,上面的其他底部边框会变得更粗,就好像它们是双边框一样。
#navbar ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#navbar li a {
display: block;
width: 60px;
padding: 16px 32px;
text-decoration: none;
text-align: center;
color: black;
border: 1px solid black;
}
#navbar a:hover {
background-color: black;
color: white;
}
#navbar a:last-child {
border-bottom: none;
}
<div>
<ul id="navbar">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="models.html">Models</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
You need your last-child
selector on the li
element.您需要
li
元素上的last-child
选择器。
#navbar li a {
display: block;
width: 60px;
padding: 16px 32px;
text-decoration: none;
text-align: center;
color: black;
border: 1px solid black;
border-bottom: none; /* add this */
}
#navbar li:last-child a {
border-bottom: 1px solid black;
}
See :last-child at css-tricks.com for more information有关更多信息,请参见css-tricks.com 的 :last-child
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.