当前位置:网站首页>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 .
边栏推荐
- Alert pop-up processing in Web Automation
- death_satan/hyperf-validate
- Linux MySQL implements root user login without password
- Differences between overloads, rewrites, abstract classes and interfaces
- Deleting MySQL under Linux
- Use of JDBC
- What is the e-commerce conversion rate so abstract?
- Development trend of mobile advertising: Leveraging stock and fine marketing
- Configure redis from 0
- Example of MVVM framework based on kotlin+jetpack
猜你喜欢

Linked list (II) - Design linked list

Linux Mysql 实现root用户不用密码登录

Promotion intégrale et ordre des octets de fin de taille

Independent station sellers are using the five e-mail marketing skills, do you know?

Xcode13.3.1 项目执行pod install后报错

Parsing ng template with let total in NZ Pagination

AutoCAD C # Polyline Small Sharp angle Detection

AutoCAD C# 多段线自相交检测

Paper recommendation: efficientnetv2 - get smaller models and faster training speed through NAS, scaling and fused mbconv

fpm工具安装
随机推荐
Teach you how to use UCOS
YYGH-BUG-02
The custom cube UI pop-up dialog supports multiple and multiple types of input boxes
API learning of OpenGL (2006) glclientactivetexture
Xcode13.3.1 项目执行pod install后报错
报错--解决core-js/modules/es.error.cause.js报错
Object对象转 List集合
使用SSM框架,配置多个数据库连接
freeswitch设置最大呼叫时长
death_ satan/hyperf-validate
整型提升和大小端字节序
Working principle of es9023 audio decoding chip
MySQL(二)——基本操作
Note that JPA uses a custom VO to receive jpql query results
Install and manage multiple versions of PHP under mac
Sklearn Feature Engineering (summary)
Linked list (III) - reverse linked list
Example of MVVM framework based on kotlin+jetpack
ThreadLocal
Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution