【发布时间】:2019-12-15 00:41:11
【问题描述】:
我正在尝试自动对齐导航栏,以便徽标和链接始终垂直对齐。我添加了一个“显示:表格;”到我的主标题和 Sublime 2 将“表”变白,这意味着它没有锁定。它还使我的徽标和链接声明中的“Table-Cell”变白。不用说,我的代码不起作用。
有人知道为什么吗?
代码如下:
<div class="header">
<img id="GovDefendersLogo" src="images/GovDefendersLogo.png">
<ol>
<a href="mailto:govdefenders@dlt.com"><li class="links">Contact Us</li></a>
<a href="blog"><li class="links">Blog</li></a>
<a href="partners/index.html"><li class="links">Partners</li></a>
<a href= "technology/index.html"><li class="links">Technology</li></a>
<a href="index.html"><li class="links">Home</li></a>
</ol>
</div>
CSS
.header {
height: 77px;
position: relative;
clear: both;
background-color: white;
border-bottom: 1px solid gray;
border-top: 1px solid gray;
box-shadow: 0 0 16px 0 rgba(50,50,50,0.3);
width: 100%;
display: table;
}
#GovDefendersLogo {
float: left;
}
ol {
list-style: none;
margin: 0;
padding: 0;
color: black;
}
.links {
float: right;
margin-left: 30px;
letter-spacing: 1px;
text-transform: uppercase;
font-weight: 400;
list-style: none;
}
#GovDefendersLogo,
.links {
display: table-cell;
vertical-align: middle;
}
【问题讨论】:
-
你的
a标签应该在ol的li标签内。
标签: html css vertical-alignment css-tables