我遇到的问题是我想让导航栏链接(主页、关于、博客)之间的分隔线在导航栏中间垂直居中。 我尝试使用 padding-top 标签,但它没有做任何事情。
另外,我不确定这是否是做我想做的最好的方法,所以如果有更好的方法在导航栏链接之间制作分隔线,请随时提出您的建议,因为我刚刚学习 CSS
代码如下:
https://jsfiddle.net/hntkv9x0/
HTML:
<body>
<div id="header"></div>
<div id="navbar">
<div class="navbarlinks">
<ul>
<li class="navbarlinks"><a class="nav" href="#">HOME</a>
<li class="navbarlinks"><a class="nav" href="#">ABOUT</a>
<li class="navbarlinks"><a class="nav" href="#">BLOG</a>
</ul
</div>
CSS:
body {
margin: 0;
padding:0;
background:#FFFFFF;
}
#header {
background: #FFDD00;
height: 150px;
}
#navbar {
background: #000000;
height: 50px;
box-shadow: 0px 0px 20px;
border-bottom: solid #FFDD00;
border-top: solid #FFDD00;
border-width: 5px;
position:relative;
}
ul{list-style-type:none;
text-align: center;
margin:0;
padding:0;
}
.navbarlinks {
color: #968517;
font-family:'Ubuntu', sans-serif;line-height:30px;
font-size:15px;
margin-left:5%;
font-style:bold;
}
li {
display: inline;
float:left;
border-right:solid #968517;
border-left:solid #968517;
border-width:1px;
margin:0% -5% 0% 0%;
}
.nav {
display: block;
width:85px;
height:30px;
margin-top:10px;
}
a:link {
text-decoration: none;
color: #968517 background:#000000;
}
a:visited {
color: #968517;
background:#000000;
}
a:hover {
color: #FFDD00;
background:#242113;
}
最佳答案
尝试将 height: 100%;
添加到包含导航栏项的 ul
和 li.navbarlinks
。
jsfiddle
关于html - 我在网站的导航栏中使用 border-left border-right 作为分隔符。我想知道如何让它们在导航栏中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33438939/