浮动 div 重叠非浮动 div

floated div Overlapping non floated div

这两个div定义在body标签中 问题是它们相互重叠 div(黄色)按预期到达页面左侧,但第二个 div(红色)没有设置浮动样式,位于第一个 div

为什么第二个 div(红色)没有出现在第一个 div 旁边,第二个 div 应该环绕第一个 div 因为浮动 属性

然而 visual studio 2010 产生了预期的结果,但 chrome、firefox、jsfiddle 没有

<div style ="background-color:Yellow;height:300px; width:300px; float:left"> </div>
<div style ="background-color:red;height:300px; width:300px"> </div>

浮动 属性 适用于您应用它的元素以及它相对的元素。如果一个元素没有浮动 属性,它不会尝试浮动到 left/right。 第二个 div 也应该有一个浮点数 属性。

请阅读此内容以使其更加清晰 - https://css-tricks.com/all-about-floats/

如果您的目标是让它们都向左浮动但不重叠,请将 float:left 添加到红色 div。

http://jsfiddle.net/42o54e4w/1/