任何人都可以解释为什么导航栏位于指定的<div id="navigation >
标记下方,查看以下代码:
<html>
<head>
<link rel="stylesheet" href="css.css"/>
</head>
<body>
<div id="container">
<div id="title">
<h1>Record Store</h1>
</div>
<div id="navigation" >
<ul class="navbar">
<li><a href="#">Home</a></li>
<li><a href="#">Vinyl Stock</a></li>
<li><a href="#">Members</a></li>
</ul>
</div>
</div>
</body>
</html>
和CSS
* {
border: 0;
padding: 0;
}
#container {
margin: auto;
width: 800px;
border: 1px solid black;
min-height: 600px;
z-index: -9;
}
#title {
margin:auto;
border: 1px solid black;
}
#navigation{
border: 1px solid black;
height: auto;
background-color: yellow;
}
.navbar {
}
.navbar ul {
}
.navbar li {
float: left;
font: bold 12px/1.2em Arial, Verdana, Helvetica;
height: auto;
list-style: none;
text-align: center;
width: 33%;
display: inline;
}
.navbar a {
border-right: 1px solid #1F5065;
color: black;
display: block;
padding: 10px 10px;
text-decoration: none;
}
如果有人能帮助我整理酒吧,我将不胜感激。我是学习CSS和HTML的初学者。
答案 0 :(得分:0)
因为您正在浮动列表元素而不清除它们。将其添加到您的CSS
.clearfix:before, .clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both; }
.clearfix { *zoom: 1; }
然后将clearfix类添加到ul.navbar
<ul class="navbar clearfix">
<li><a href="#">Home</a></li>
<li><a href="#">Vinyl Stock</a></li>
<li><a href="#">Members</a></li>
</ul>