我有兩個DIV(Nav和Main)。當他們的寬度增加到100%時,第二個總是漂浮在第一個下面。如果我將第一個DIV的寬度更改爲19%,將第二個DIV的寬度更改爲79%,則它們並排浮動,但右側有2%的空白區域。如何獲得寬度相加的100%的兩個DIV?
我怎樣才能讓2個DIV並排坐在一起(即使在調整窗口大小後),以便它們合併填充頁面寬度的100%?
下面是代碼,它是在Chrome正在測試:
<html>
<head>
<title>Space</title>
<style>
#header h1 {
text-align: center;
font-size: 40pt;
font-family: Century Gothic;
}
#header {
background: aqua;
}
#nav {
height: 100%;
width: 19%;
float: left;
background: lightblue;
}
#nav p {
font-size: 20pt;
font-family: Century Gothic;
color: yellow;
}
#main {
float: left;
padding-left: 20px;
background: linear-gradient(white, blue);
width: 79%;
height: 100%;
}
</style>
</head>
<body>
<div id="header">
<br>
<h1>All About Space</h1>
<br>
</div>
<div id="nav">
<p>Mercury</p>
<p>Venus</p>
<p>Earth</p>
<p>Mars</p>
<p>Saturn</p>
<p>Jupiter</p>
<p>Uranus</p>
<p>Neptune</p>
</div>
<div id="main">
<h3>This website is all about space</h3>
<img src="http://marshall.org/wp-content/themes/marshall/img/featured-space-policy.jpg" alt="" height="200px" width="400px">
<p>Clicking on the links to the right and you will learn all about the planets of the solar system</p>
<p>Maybe one day we will all be able to visit some of them!</p>
</div>
</body>
</html>
添加一個包裝div作爲這些2 div的容器,並有display:flex包裝風格 –