<分区>
<分区>
当我想将一个div float 在另一个div 中时,问题就会出现。
<div id="main">
<div id="anotherDiv">
<h1>Test</h1>
</div>
</div>
这是我的样式表:
#main{ background-color:red; padding:20px; }
#anotherDiv{ background-color:blue; }
这是我没有 float 的页面:
但这是我添加以下样式时的阶梯表:
#anotherDiv{ float:left; }
但是我想要这样的东西:
我能做什么?
最佳答案
只需将 overflow:auto
添加到 #main
即可:
#main {
background-color:red;
padding:20px;
overflow:auto;
}
这将在没有任何不必要的 HTML 元素的情况下恢复您寻找的父 div 的行为。
关于html - 当我在 HTML 中将我的 div 标签 float 到另一个 div 中时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31165315/