当前位置:网站首页>Floating and positioning
Floating and positioning
2022-06-28 06:25:00 【Nick_ Zhang】
1. float
Property value | describe |
---|---|
left | Element floating to the left |
right | The element floats to the right |
none | Element does not float |
Elements do not occupy positions after floating , Off stream , But not out of the text stream , The nearest words will surround him
<style> .box {
/* overflow: hidden; */
}
.box::after {
content: "";
display: block;
clear: both;
}
.red {
float: left;
width: 100px;
height: 100px;
background: red;
}
/* But if you use absolute positioning , The element will be separated from the document flow , Also out of the text stream */
.green {
float: left;
width: 100px;
height: 100px;
background: green;
}
.blue {
float: left;
width: 100px;
height: 100px;
background: blue;
}
.footer{
width:400px;
height:200px;
background:pink
}
.both {
/* clear: both; */
}
</style>
<div class="box">
<div class="red"></div>
<div class="green"></div>
<div class="blue"></div>
<div class="both"></div>
<!-- <p>CSS There are three basic positioning mechanisms : Ordinary flow ( The document flow )、 Floating and absolute positioning .</p> -->
</div>
<div class="footer"></div>
1.1 Remove the floating
1. Add height to parent element
.box{
height:100px;
}
2. Set parent element overflow:hidden
.box{
overflow:hidden
}
3. Parent definition Pseudo elements ::after
.box::after {
content: "";
display: block;
clear: both;
}
4. Blank at the end div, Or add... To the affected elements clear:both
.both {
clear: both;
}
1.2 Trigger BFC
BFC(Box Formatting Context, Block level formatting context ) It's an isolated container on the page , The child elements inside the container do not affect the elements outside .
A box is not set height when , When all content elements are floating , Can't hold themselves up , Therefore, you need to create BFC To avoid this situation
How to create BFC:
1.float Not for none
2.position by fixed or absolute
3.display The value of is inline-block、flex perhaps table
4.overflow Not for visible
BFC Other functions of :
1. You can cancel the box margin Collapse ;
2. Can prevent elements from being overwritten by floating elements .
2. location
The positioning of child elements relative to the parent element means that the child element is based on the nearest It's positioned ( absolute 、 Fixed or relative positioning ) Parent element of Positioning , If none of the parent elements are located , According to body Root element ( Browser window ) Positioning .
边栏推荐
- MySQL(二)——基本操作
- Boost the rising point | yolov5 combined with alpha IOU
- socke.io长连接实现推送、版本控制、实时活跃用户量统计
- FPGA - 7 Series FPGA selectio -07- iserdese2 of advanced logic resources
- eyebeam高级设置
- Working principle of es9023 audio decoding chip
- 链表(一)——移除链表元素
- 阿里云短信服务(完整指南),短信发送功能实现。
- 4~20mA输入/0~5V输出的I/V转换电路
- 记JPA使用自定义VO接收 JPQL查询结果
猜你喜欢
整型提升和大小端字节序
搭建你jmeter+jenkins+ant
移动广告发展动向:撬动存量,精细营销
Linked list (II) - Design linked list
Oracle condition, circular statement
How the third-party libraries in cocoapod reference local header files
Parsing ng template with let total in NZ Pagination
freeswitch使用mod_shout模块播放mp3
链表(三)——反转链表
Sharing tips for efficient scripting
随机推荐
JQ picture amplifier
D3D11_ Chili_ Tutorial (3): design a bindable/drawable system
Iframe switching in Web Automation
使用SSM框架,配置多个数据库连接
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException:异常解决
Freeswitch uses origin to dialplan
Linux MySQL implements root user login without password
API learning of OpenGL (2007) gltexcoordpointer
搭建你jmeter+jenkins+ant
ThreadLocal
OpenGL API learning (2008) client server client server
How to open UMD, KMD log and dump diagrams in CAMX architecture
职场IT老鸟的几点小习惯
JDBC学习(一)——实现简单的CRUD操作
How to add live chat in your Shopify store?
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Use of JDBC
Alibaba cloud SMS service (Complete Guide), SMS sending function implementation.
FPGA - 7系列 FPGA SelectIO -07- 高级逻辑资源之ISERDESE2
Linked list (III) - reverse linked list