当前位置:网站首页>清除浮动的方式
清除浮动的方式
2022-07-06 05:33:00 【雷haoming】
问题
html:
<div class="f-box">
<div class="box1"></div>
<div class="box2"></div>
</div>
css:
.f-box {
background-color: pink;
}
.box1, .box2 {
width: 200px;
height: 200px;
}
.box1 {
float: left;
background: tomato;
}
.box2 {
float: left;
background: greenyellow;
}
效果:
父元素没有被撑开,所以没有显示出来。
解决办法
一、添加空标签
在元素末尾加一个空标签并且设置样式clear: both
html:
<div class="f-box">
<div class="box1"></div>
<div class="box2"></div>
<div style="clear: both"></div>
</div>
二、将父元素设置为BFC
设置父元素样式overflow: hidden;
或者display: flex;
等等。创建BFC
.f-box {
background-color: pink;
overflow: hidden;
}
三、使用伪元素
设置父元素after
伪元素清除浮动
其实这种方式类似第一种,只是用为元素代替了空标签
.f-box::after{
content:'';
display:block;
height:0;
clear:both;
visibility:hidden;
}
解决后
边栏推荐
- How to download GB files from Google cloud hard disk
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Detailed summary of SQL injection
- 初识CDN
- 2022半年总结
- Game push: image / table /cv/nlp, multi-threaded start!
- [detailed explanation of Huawei machine test] statistics of shooting competition results
- RustDesk 搭建一个自己的远程桌面中继服务器
- 05. 博客项目之安全
- Note the various data set acquisition methods of jvxetable
猜你喜欢
剑指 Offer II 039. 直方图最大矩形面积
P2802 回家
Vulhub vulnerability recurrence 73_ Webmin
Sword finger offer II 039 Maximum rectangular area of histogram
Nacos - TC Construction of High available seata (02)
图数据库ONgDB Release v-1.0.3
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
指針經典筆試題
Codeforces Round #804 (Div. 2) Editorial(A-B)
Fluent implements a loadingbutton with loading animation
随机推荐
UCF(2022暑期团队赛一)
(column 22) typical column questions of C language: delete the specified letters in the string.
Excel转换为Lua的配置文件
Steady, 35K, byte business data analysis post
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
flutter 实现一个有加载动画的按钮(loadingButton)
CUDA11.1在线安装
jdbc使用call调用存储过程报错
After the project is released, index Html is cached
UCF(暑期团队赛二)
[effective Objective-C] - memory management
Knowledge points of circular structure
Pickle and savez_ Compressed compressed volume comparison
Nacos - TC Construction of High available seata (02)
Promotion hung up! The leader said it wasn't my poor skills
[mask requirements of OSPF and Isis in multi access network]
27io stream, byte output stream, OutputStream writes data to file
PDK工藝庫安裝-CSMC
How to download GB files from Google cloud hard disk
C Advanced - data storage (Part 1)