我正在创建一个网站,但我在定位 div 时遇到了一些问题。
我的 content div
没有定位在 navigation-bar div
旁边,即使我将它们都向左浮动也是如此。
这是 HTML 代码。
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
<div id="title">
Sample Title
</div>
<div id="navigation-bar">
Home
<br>
<br>
Products
<br>
<br>
</div>
<div id="content">
content goes here
</div>
</body>
</html>
这里是theme.css文件
#title
{
color: black;
padding: 20px;
font-size: 250%;
padding: 2%;
width: 70%;
height: 10%;
border: 4px solid blue;
}
#navigation-bar
{
background-color: #606060;
width: 15%;
height: 70%;
color: white;
text-align: center;
padding: 2%;
font-size: 80%;
border: 4px solid blue;
}
#content
{
border: 4px solid blue;
float: left;
width: 20%;
height: 70%;
}
问题是 navigation-bar div
和 content div
不会彼此相邻放置,而是 content div
将自己定位在下方导航栏 div
。
谢谢。
最佳答案
你在哪里使用 float: left;
用于 #navigation-bar
?
#navigation-bar
{
background-color: #606060;
width: 15%;
height: 70%;
color: white;
text-align: center;
padding: 2%;
font-size: 80%;
border: 4px solid blue;
float: left; <--- Add this Here
}
关于html - 为什么一个 div 没有定位在另一个 div 旁边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14006271/