css - 防止 float 元素插入其他元素

标签 css

我的代码是这样的:

<div class="padding5">
<div id="div1" class="float_left wh50"></div>
<div id="div2" class="float_left h50">Long text goes right here, Lorem Ipsum Dolor Sit Amet.Long text goes right here, Lorem Ipsum Dolor Sit Amet.Long text goes right here, Lorem Ipsum Dolor Sit Amet.Long text goes right here, Lorem Ipsum Dolor Sit Amet.</div>                        
<div id="div3" class="float_right wh50"></div>
<div id="div4" class="float_right wh50"></div>                                                                                                                          
<div class="clear"></div>                                                 
</div>

我的 CSS 是这样的:

<style>
.padding5{padding:5px;}
.wh50{width:50px;height:50px;}
.h50{height:50px;}
.float_left{float:left;}
.float_right{float:right;}
</style>

现在,如果我调整窗口大小(并使其变小),我希望 div id=2 中的内容将单词分成新行,但事实并非如此。不断将其他元素推到后面。

最佳答案

.wh50 类中删除 height。或者将其设置为 min-height: 50px;。高度声明导致 div3div4 看起来好像没有被清除。

.padding5{padding:5px;}
.wh50{width:50px;height:50px;}
.h50{min-height:50px;}
.float_left{float:left;}
.float_right{float:right;}

关于css - 防止 float 元素插入其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916256/

相关文章:

html - 如何使 div 不滚动、固定并保持基于父容器的宽度

css - 将 div 宽度设置为没有内联 block 的内容,并使 div 彼此居中对齐

css - 为什么 bootstrap css (3.2) 可以在移动端和桌面端工作

javascript - 文本在 jQuery 中仅在第一行之后居中

javascript - (无框架 - 纯 JS)使用 JS 对从 API 中提取的表进行分页

html - CSS: make overflow-x: hidden 真的隐藏了吗?

CSS 最佳实践问题

html - 两个图像相对的 Z-index

css - 在 WordPress 菜单中,我想将顶部和底部箭头添加到子菜单内容以进行滚动

javascript - 将 javascript 淡入应用到 4 个 div,间隔为 2 秒