尝试了一切,将原始代码从w3schools中取出并尝试自己编辑但在此问题上丢失了。我尝试过显示:内联;并尝试在这里的问题的一些其他答案,但无济于事。
/* Div setup */
.wrapper {
width: 650px;
display: block;
margin: 0 auto;
font-family: Verdana;
}
.header {
background-color:#333;
padding: 0 0 0 20px;
width:100%;
height: 50px;
color: white;
text-align: left;
line-height: 50px;
white-space: nowrap;
font-size: 20px;
}
.nav {
width: 100px;
float; none;
font-size: 12px;
}
.content {
width:500px;
float:left;
font-size: 12px;
}
.side {
width:150px;
float:left;
font-size: 12px;
}
.footer {
background-color:black;
clear: both;
width: 100%;
height: 30px;
text-align: center;
color: white;
line-height: 30px;
white-space: nowrap;
font-size: 12px;
}
/* Navigation Bar Settings */
.nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #666;
width: 100%;
}
.nav li {
display: inline-block;
}
.nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav li a:hover {
background-color: #111;
}

<div class="wrapper">
<div class="header">
<p>The <b>Time Traveller</b> Bookstore</p>
</div>
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">The Vault</a></li>
<li><a href="#">Order</a></li>
<li><a href="#">Report</a></li>
</ul>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec justo libero, feugiat at est nec, fringilla pellentesque massa. Aenean mattis mauris quis nunc interdum tincidunt. Quisque ipsum est, pharetra aliquam dapibus vestibulum, laoreet sit amet metus. Nulla vitae lorem eros. In dictum tincidunt nisl in eleifend. Pellentesque molestie nulla et eros vestibulum, ut scelerisque enim lacinia. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin nec commodo tellus.</p>
<p>Fusce facilisis, ex eu tristique aliquet, nulla sapien fermentum nunc, at elementum ex leo eget metus. Nunc interdum sapien lacus, eu iaculis eros dapibus eget. Ut vitae orci varius, elementum libero nec, semper elit. Aliquam pretium rhoncus arcu, ultrices consectetur magna tempus vel. Suspendisse eu euismod lectus. Proin ut diam ornare ligula tincidunt ornare eget fermentum nisi. Pellentesque ligula augue, interdum a turpis eu, lacinia congue odio. Integer ut lorem ut nisl tincidunt tempus eu id purus. Quisque vehicula ipsum sed nulla commodo, in semper augue cursus. Aenean faucibus odio mi, congue tempus ante iaculis nec. Etiam non elit at sem blandit rhoncus ut non tellus. Donec condimentum augue non nulla vestibulum, sit amet interdum quam fringilla. Maecenas scelerisque aliquam purus, at ultricies odio.</p>
</div>
<div class="side">
<p>Advert</p>
</div>
<div class="footer">
<p>Footer</p>
</div>
</div>
&#13;
目前正在垂直输出。
提前感谢您的帮助。
答案 0 :(得分:1)
.nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #666;
width: 100%;
}
.nav li {
display: inline-block; /* simply set to inline-block */
}
.nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav li a:hover {
background-color: #111;
}
&#13;
<div class="nav">
<ul>
<li><a href="#">Home</a>
</li>
<li><a href="#">About Us</a>
</li>
<li><a href="#">The Vault</a>
</li>
<li><a href="#">Order</a>
</li>
<li><a href="#">Report</a>
</li>
</ul>
</div>
&#13;
答案 1 :(得分:0)
删除width: 100px
上的.nav
并在display: inline-block
上设置.nav li
/* Div setup */
.wrapper {
width: 650px;
display: block;
margin: 0 auto;
font-family: Verdana;
}
.header {
background-color:#333;
padding: 0 0 0 20px;
width:100%;
height: 50px;
color: white;
text-align: left;
line-height: 50px;
white-space: nowrap;
font-size: 20px;
}
.nav {
/*width: 100px;*/ /* 1 */
float: none;
font-size: 12px;
}
.nav li {
display: inline-block; /* 2 */
}
.content {
width:500px;
float:left;
font-size: 12px;
}
.side {
width:150px;
float:left;
font-size: 12px;
}
.footer {
background-color:black;
clear: both;
width: 100%;
height: 30px;
text-align: center;
color: white;
line-height: 30px;
white-space: nowrap;
font-size: 12px;
}
/* Navigation Bar Settings */
.nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #666;
width: 100%;
}
.nav li {
display: inline-block;
}
.nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav li a:hover {
background-color: #111;
}
<div class="wrapper">
<div class="header">
<p>The <b>Time Traveller</b> Bookstore</p>
</div>
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">The Vault</a></li>
<li><a href="#">Order</a></li>
<li><a href="#">Report</a></li>
</ul>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec justo libero, feugiat at est nec, fringilla pellentesque massa. Aenean mattis mauris quis nunc interdum tincidunt. Quisque ipsum est, pharetra aliquam dapibus vestibulum, laoreet sit amet metus. Nulla vitae lorem eros. In dictum tincidunt nisl in eleifend. Pellentesque molestie nulla et eros vestibulum, ut scelerisque enim lacinia. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin nec commodo tellus.</p>
<p>Fusce facilisis, ex eu tristique aliquet, nulla sapien fermentum nunc, at elementum ex leo eget metus. Nunc interdum sapien lacus, eu iaculis eros dapibus eget. Ut vitae orci varius, elementum libero nec, semper elit. Aliquam pretium rhoncus arcu, ultrices consectetur magna tempus vel. Suspendisse eu euismod lectus. Proin ut diam ornare ligula tincidunt ornare eget fermentum nisi. Pellentesque ligula augue, interdum a turpis eu, lacinia congue odio. Integer ut lorem ut nisl tincidunt tempus eu id purus. Quisque vehicula ipsum sed nulla commodo, in semper augue cursus. Aenean faucibus odio mi, congue tempus ante iaculis nec. Etiam non elit at sem blandit rhoncus ut non tellus. Donec condimentum augue non nulla vestibulum, sit amet interdum quam fringilla. Maecenas scelerisque aliquam purus, at ultricies odio.</p>
</div>
<div class="side">
<p>Advert</p>
</div>
<div class="footer">
<p>Footer</p>
</div>
</div>