简体   繁体   English

列未环绕浮动元素

[英]Column not wrapping around floated elements

 .container { background-color: lightgreen; } .column { width: 31.33%; background-color: green; float: left; margin: 0 1%; } .column:last-child { float: none; } 
 <div class='container'> <div class='column'>Column 1</div> <div class='column'>Column 2</div> <div class='column'>Column 3Column 3Column 3Column 3Column 3Column 3Column 3</div> </div> 

Why does column three not wrap around like this: 为什么第三列没有像这样环绕: 在此处输入图片说明

There is enough space for it on the right of the floated elements. 浮动元素的右侧有足够的空间。

Add width: 100% to the .column:last-child. 向.column:last-child添加宽度:100%。

.column:last-child {
    float: none;
  width: 100%;
}

The answer why this happens is pretty much the answer from this 之所以出现这种情况的答案几乎是答案这个

Here's a fiddle demonstrating that the 3rd column is below the floated columns, and it's text content is simply wrapping around (below in this case) the floated column. 这是一个小提琴,表明第三列在浮动列的下方,并且它的文本内容只是在浮动列(在此情况下)周围。

(simply made some backgrounds translucent) (仅使某些背景变得半透明)

.column {
    width: 31.33%;
    background-color: rgba(0, 255,0, .5);
    float: left;
    margin: 0 1%;
}

.column:last-child {
    float: none;
  background: red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM