我不明白为什么rightcontent和leftcontent div不会保留在中心体div中,当“< p>”的数量增加时。嵌套div应根据其中的div调整大小,但它们不
<html>
<style media="screen" type="text/css">
body {
background-color: #efefef;
}
h1 {
color: white;
text-align: center;
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
p {
font-family: verdana;
font-size: 20px;
}
#centerbody { /*this is the style of the main body white box */
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
border-radius: 5px 5px 5px 5px;
padding: 20px;
margin: 100px 50px 100px 50px;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 20px;
}
#rightContent {
float:right;
width: 50%;
margin-bottom: 20px;
}
#leftContent {
float:left;
width: 50%;
margin-bottom: 20px;
}
</style>
<body>
<div id="centerbody">
<div id="rightContent">
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
</div>
<div id="leftContent">
right side stuff
</div>
</div>
</body>
</html>
我想这是因为你的父母DIV其实没有具有特定的宽度。 –
https://css-tricks.com/snippets/css/clear-fix/可能会帮助 –