html - 我在网站的导航栏中使用 border-left border-right 作为分隔符。我想知道如何让它们在导航栏中居中

标签 html css navbar

我遇到的问题是我想让导航栏链接(主页、关于、博客)之间的分隔线在导航栏中间垂直居中。 我尝试使用 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%; 添加到包含导航栏项的 ulli.navbarlinksjsfiddle

关于html - 我在网站的导航栏中使用 border-left border-right 作为分隔符。我想知道如何让它们在导航栏中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33438939/

相关文章:

javascript - 如何建立链接 - 链接到 DIV?

javascript - 如何在 html div 的中间打印/附加单击按钮的值?

javascript - 如何为宽度 :auto div when new text is added to it in css3? 设置动画

HTML5 输入类型 'Number' 模式未被强制执行

html - CSS 导航链接在悬停时没有改变

HTML 将导航栏右对齐,图像适合页面

html - 将 div 推到 <a> 类上

html - (非空)自闭合标签在 HTML5 中有效吗?

javascript - 让父级滚动到某个点,然后子级在父级内部滚动

c# - GridView 列不断缩小