当前位置:网站首页>清除浮动的方式
清除浮动的方式
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;
}
解决后
边栏推荐
- Problems encountered in installing mysql8 on MAC
- 04. 项目博客之日志
- Vulhub vulnerability recurrence 69_ Tiki Wiki
- Improve jpopup to realize dynamic control disable
- Vulhub vulnerability recurrence 67_ Supervisor
- 算法-- 爬楼梯(Kotlin)
- Web Security (V) what is a session? Why do I need a session?
- (column 22) typical column questions of C language: delete the specified letters in the string.
- [leetcode] 18. Sum of four numbers
- UCF (2022 summer team competition I)
猜你喜欢
27io stream, byte output stream, OutputStream writes data to file
什么是独立IP,独立IP主机怎么样?
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
Fluent implements a loadingbutton with loading animation
Promise summary
【torch】|torch.nn.utils.clip_grad_norm_
[leetcode] 18. Sum of four numbers
Nacos TC setup of highly available Seata (02)
Figure database ongdb release v-1.0.3
B站刘二大人-数据集及数据加载 Lecture 8
随机推荐
jdbc使用call调用存储过程报错
Unity Vector3. Use and calculation principle of reflect
B站刘二大人-数据集及数据加载 Lecture 8
Please wait while Jenkins is getting ready to work
应用安全系列之三十七:日志注入
毕业设计游戏商城
03. Login of development blog project
First acquaintance with CDN
什么是独立IP,独立IP主机怎么样?
[JVM] [Chapter 17] [garbage collector]
Selective parameters in MATLAB functions
Application Security Series 37: log injection
Steady, 35K, byte business data analysis post
pix2pix:使用条件对抗网络的图像到图像转换
Redis消息队列
算法-- 爬楼梯(Kotlin)
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
Talking about the type and function of lens filter
[detailed explanation of Huawei machine test] statistics of shooting competition results
Implementing fuzzy query with dataframe