.header2
{
background-color:#CDD1CD; /*have to change */
/*padding: 15px 0;*/
}
.header1
{
background-color: #60db60; /* have to change */
padding: 10px 0;
}
/*Fixed header properties */
.fixed
{
position: fixed;
top:0; left:0;
width: 100%;
}
.right
{
float: right;
}
<div class="headers header1" id="header1">
<div class="logo"></div>
<div class="slogan"></div>
</div>
<div class="headers header2 clearboth" id="header2">
<nav class="login_links">
<ul>
<li>Are you a member?</li>
<li><a>Register</a></li>
<li><a>login</a></li>
</ul>
</nav>
</div>
您可以看到两个标题之间的差距。如果我将 float:left
给 nav
它将被修复。可能是什么原因?有哪些可能性。
编辑:
经过一些编辑,我发现它是由 ul
元素的 margin
引起的。
ul
{
margin: 0;
}
这个利润从哪里来?
最佳答案
ul
标签有默认边距。有关更全面的讨论,请参见此处:
Unordered List (<ul>) default indent
ul {
margin:0px;
}
乍看之下,原因是为了在我们的技术还不那么先进的那一天向后兼容。
关于html - 为什么我们需要 float :left in this header?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29326528/