子元素浮动,父元素撑不开height=0解决方法
来源:互联网 发布:mac需要清理软件 编辑:程序博客网 时间:2024/06/04 17:54
如代码所示,div1,div2,div3都是左浮动的。父元素box撑不开。
<div class="box"> <div class="div div1"></div> <div class="div div2"></div> <div class="div div3"></div> <!--<p style="clear: both"></p>--> </div>解决方法:
1.直接设置父元素height
.box{ border: 1px solid #00d6b2; /*height: 102px;*/ }
2.父元素设置overflow:hidden
.box{ border: 1px solid #00d6b2; /*overflow: hidden;*/ }
3.父元素内末尾添加一个元素
意思就是在父元素内末尾添加一个元素 清楚浮动clear:both;
<div class="box"> <div class="div div1"></div> <div class="div div2"></div> <div class="div div3"></div> <!--<p style="clear: both"></p>--> </div>
4.伪类方法 父元素:after
意思就是在父元素后面加一个空格,设置这个空格clear:both;display:block;visibility:hidden;height:0;
.box:after{ content: " "; clear: both; display: block; visibility: hidden; height: 0; }最后,完整代码:
<!DOCTYPE html><html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Title</title> <script type="text/javascript"> </script> <style type="text/css"> .box{ border: 1px solid #00d6b2; /*height: 102px;*/ /*overflow: hidden;*/ } .box:after{ content: " "; clear: both; display: block; visibility: hidden; height: 0; } .div{ border: 1px solid black; float: left; width: 100px; height: 100px; } .div1{ background-color: red; } .div2{ background-color: greenyellow; } .div3{ background-color: pink; } </style></head><body> <div class="box"> <div class="div div1"></div> <div class="div div2"></div> <div class="div div3"></div> <!--<p style="clear: both"></p>--> </div></body></html>
阅读全文
0 0
- 子元素浮动,父元素撑不开height=0解决方法
- 子元素浮动,父元素高度为0解决方法
- 子元素浮动,父元素高度为0解决方法
- 子元素浮动后,父元素设置的min-height会出现无效的情况。
- 清除浮动--子元素float导致父元素height塌陷解决方案
- 子元素设置浮动样式,父元素高度为0
- 解决子元素浮动父元素高度为0
- 浮动子元素的父元素高度为0,怎么办
- 子元素浮动 父元素自适应高度
- 子元素浮动,父元素高度为0,要把父元素清除浮动..
- 浮动元素无法撑开父元素--解决方法
- 父容器display:flex后,子元素的内部元素height:100%无效解决方法
- 父容器display:flex后,子元素的内部元素height:100%无效解决方法
- 浮动子元素不能撑起父元素最有效解决方法
- DIV边框重叠变粗解决方案(子元素浮动导致父元素失去高度解决方法)
- 子元素浮动造成父元素坍塌的原因分析和解决方法
- 【css】浮动的影响及解决方法(父元素无高度,而子元素有高度)
- 父元素设置min-height子元素设置100%问题
- 【BFS && 树】UVALive
- 表单序列化 不根据name value 根据自定义key value完成
- 基于 Viewpager,实现了 Gallery 效果
- 关于列表
- 支持向量机
- 子元素浮动,父元素撑不开height=0解决方法
- Android截屏分享
- Ch’s gift HDU
- SpringMVC编程<一>
- Spring:创建Bean的几种方式
- 4412内核移植
- java路径分隔符转换
- Halcon学习笔记(二) 算子学习
- Spring boot上集成Jedis