HTML&CSS - 在标题和按钮标题中居中放置文本
问题描述:
如何将我的导航链接对齐到标题? 这就是我目前所拥有的: 但是,我真的想要链接在标题内垂直对齐,如下所示:
我该怎么做? 以下是我的CSS & HTML。HTML&CSS - 在标题和按钮标题中居中放置文本
html, body {
margin: 0;
padding: 0;
}
body {
font-family: 'Open Sans', sans-serif;
}
.wrapper {
width: 1100px;
max-width: 90%;
margin: 0 auto;
}
#top_header {
position: fixed;
left: 0px;
top: 0px;
right: 0px;
background-color: #26ABF5;
height: 70px;
vertical-align: middle;
}
#logo_top {
display: inline-block;
width: 53px;
padding-top: 8px;
}
#main_nav {
display: inline-block;
font-size: 12px;
padding-left: 170px;
}
#main_nav a {
color: #fff;
font-weight: 400;
text-decoration: none;
margin-left: 6em;
}
.button {
float: right;
justify-content: center;
display: flex;
width: 101px;
margin-top: 14px;
padding-top: 9px;
padding-bottom: 9px;
border-radius: 2px;
background-color: #fff;
text-decoration: none;
font-family: 'Open Sans', sans-serif;
color: #26abf5;
font-size: 13px;
font-weight: 600;
}
<body>
<header id="top_header">
<div class="wrapper">
<a href="index.html"><img id="logo_top" draggable="false" src="images/logo1.png"></a>
<nav id="main_nav">
<a href="#">FORSIDE</a>
<a href="#">HVAD TILBYDER VI?</a>
<a href="#">PRISER</a>
<a href="#">OM OS</a>
</nav>
<a class="button" href="#">LOG IND</a>
</div>
</body>
答
使用行高度vertical-align
。我在#main_nav
中添加该行。
编辑:添加float: left;
为您的徽标图像。
html, body {
margin: 0;
padding: 0;
}
body {
font-family: 'Open Sans', sans-serif;
}
.wrapper {
width: 1100px;
max-width: 90%;
margin: 0 auto;
}
#top_header {
position: fixed;
left: 0px;
top: 0px;
right: 0px;
background-color: #26ABF5;
height: 70px;
vertical-align: middle;
}
#logo_top {
display: inline-block;
float: left;
width: 53px;
padding-top: 8px;
}
#main_nav {
display: inline-block;
font-size: 12px;
line-height: 70px;
padding-left: 170px;
}
#main_nav a {
color: #fff;
font-weight: 400;
text-decoration: none;
margin-left: 6em;
}
.button {
float: right;
justify-content: center;
display: flex;
width: 101px;
margin-top: 14px;
padding-top: 9px;
padding-bottom: 9px;
border-radius: 2px;
background-color: #fff;
text-decoration: none;
font-family: 'Open Sans', sans-serif;
color: #26abf5;
font-size: 13px;
font-weight: 600;
}
<body>
<header id="top_header">
<div class="wrapper">
<a href="index.html"><img id="logo_top" draggable="false" src="images/logo1.png"></a>
<nav id="main_nav">
<a href="#">FORSIDE</a>
<a href="#">HVAD TILBYDER VI?</a>
<a href="#">PRISER</a>
<a href="#">OM OS</a>
</nav>
<a class="button" href="#">LOG IND</a>
</div>
</body>
这没有做什么吗?我可以看到,它以您的示例为中心,但是当我使用添加的徽标图像测试它时,没有任何反应。 – Jakob
此外,这是一个图像的标志,如果你想测试它: – Jakob
http://i.imgur.com/VaaVzDp.png – Jakob