到目前为止,这是我的代码。问题在于顶部栏太细,意味着顶部链接周围有20px的填充,但是顶部栏总共只有40px高,因此似乎没有考虑链接本身的高度(即酒吧应该更高)。我该如何解决?
body {
padding: 0;
margin: 0;
background-color: white;
font-family: sans-serif;
}
header {
display: block;
padding: 20px;
background-color: #F9F9F9;
}
#headerbar {
position: relative;
}
.container {
width: 80%;
max-width: 1000px;
margin: 0 auto;
}
.logo {
position: absolute;
left: 0;
}
.post {
position: absolute;
right: 0;
}
<header>
<div id="headerbar" class="container">
<a href="#" class="logo">Logo</a>
<a href="#" class="post">Post</a>
</div>
</header>
最佳答案
对.logo
和.post
类的更改
body {
padding: 0;
margin: 0;
background-color: white;
font-family: sans-serif;
}
header {
display: block;
padding: 20px;
background-color: #F9F9F9;
}
#headerbar {
position: relative;
}
.container {
width: 80%;
max-width: 1000px;
margin: 0 auto;
}
.logo {
position: relative;
}
.post {
position: relative;
float: right;
}
<header>
<div id="headerbar" class="container">
<a href="#" class="logo">Logo</a>
<a href="#" class="post">Post</a>
</div>
</header>
关于html - 条高忽略文本本身的高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35008996/