当前位置:网站首页>清除浮动的方式
清除浮动的方式
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;
}
解决后
边栏推荐
- Excel转换为Lua的配置文件
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
- flutter 实现一个有加载动画的按钮(loadingButton)
- Vulhub vulnerability recurrence 71_ Unomi
- [mask requirements of OSPF and Isis in multi access network]
- [QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
- 02. Develop data storage of blog project
- MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
- UCF (2022 summer team competition I)
猜你喜欢
Modbus协议通信异常
Codeforces Round #804 (Div. 2) Editorial(A-B)
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
剑指 Offer II 039. 直方图最大矩形面积
Check the useful photo lossless magnification software on Apple computer
59. Spiral matrix
[leetcode16] the sum of the nearest three numbers (double pointer)
(column 22) typical column questions of C language: delete the specified letters in the string.
js Array 列表 实战使用总结
CUDA11.1在线安装
随机推荐
Application Security Series 37: log injection
04. Project blog log
指针经典笔试题
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
Huawei od computer test question 2
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
Text classification still stays at Bert? The dual contrast learning framework is too strong
指針經典筆試題
[Tang Laoshi] C -- encapsulation: classes and objects
【SQL server速成之路】——身份验证及建立和管理用户账户
Web Security (VI) the use of session and the difference between session and cookie
【华为机试真题详解】检查是否存在满足条件的数字组合
How to download GB files from Google cloud hard disk
P2802 回家
01. Project introduction of blog development project
HAC集群修改管理员用户密码
CUDA11.1在线安装
Yyds dry inventory SSH Remote Connection introduction
Note the various data set acquisition methods of jvxetable
【torch】|torch. nn. utils. clip_ grad_ norm_