当前位置:网站首页>Flex layout and usage
Flex layout and usage
2022-07-07 04:44:00 【From one to one】
Key summary :
- Add elastic layout :display:flex;
- Center the spindle :justify-content: center;
- The spindle spacing is between children :justify-content: space-between;
- The distance between all parts of the spindle is equal :justify-content: space-evenly;
- The spindle spacing is surrounded on both sides :justify-content: space-around;
- The side axis is centered :align-items: center;
- A child of the side axis is centered :align-self:center;
- When the child has no width , The child width is the content width
- When the child has no height , The height of the child is the height of the container
Usage mode :
Components :
- Elastic container ( Parent )
- Elastic box ( Sub level )
- Spindle
- Side axle / Cross shaft
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
}
.box {
/* Visual effect : The children are arranged in a row / Horizontal arrangement */
/* Horizontal arrangement : The default spindle is horizontal , Elastic boxes are arranged along the main axis */
display: flex;
height: 200px;
margin-top: 30px;
border: 1px solid #000;
}
.box div {
/* When the child has no width set , The width of the box is the width of the content */
/*width: 100px;*/
height: 100px;
background-color: pink;
}
</style>
Spindle alignment :
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
/* effect 1: In the middle */
/*justify-content: center;*/
/* effect 2: The spacing is in the elastic box ( Sub level ) Between */
/*justify-content: space-between;*/
/* effect 3: All places are equally spaced */
/*justify-content: space-evenly;*/
/* effect 4: The spacing is surrounded on both sides of the child */
/* Visual effect : The distance between children is the distance between the two ends of the parent 2 times */
justify-content: space-around;
width: 400px;
height: 200px;
margin:30px auto;
border: 1px solid #000;
}
.box div {
width: 100px;
height: 100px;
background-color: pink;
}
</style>
Side axis alignment :
- Control all children : to Father Element to add align-items: Property value ;
- Control a child : to Son Element to add align-self: Property value ;
stretch Is the default value of the side axis , In this mode Children have no height when , The height will be stretched to the same height as the parent .
<body>
<div class="box">
<div>1111</div>
<div>2</div>
<div>3</div>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
/* effect 1: All children are centered */
/* align-items: center; */
/* effect 3: The tensile , The default value is ( Existing status , When testing, remove the height of children ) */
align-items: stretch;
width: 400px;
height: 200px;
margin: 30px auto;
border: 1px solid #000;
}
.box div {
width: 100px;
/* height: 100px; */
background-color: pink;
}
/* effect 2: Set the side axis alignment of an elastic box separately */
.box div:nth-child(2) {
/* align-self:center ; */
}
</style>
Expansion ratio :
to Son Element to add flex: An integer value ; The integer value is occupy parent Remaining dimensions Number of copies .
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
}
.box {
display: flex;
width: 400px;
height: 300px;
margin: 30px auto;
border: 1px solid #000;
}
.box div {
height: 200px;
margin: 0 10px;
background-color: pink;
}
.box div:nth-child(1) {
width: 50px;
}
.box div:nth-child(2) {
/* The number of copies of the remaining size of the parent */
flex: 3;
}
.box div:nth-child(3) {
flex: 1;
}
</style>
The above code , Sub level 1 For a fixed width , Sub level 2、3 Is the occupation width . Parent width minus child 1 Size and children 2 And children 3 After the size of the outer margin , The remaining dimensions are divided into 3+1=4 Share , Including children 2 Width share 3 Share , Sub level 3 Width share 1 Share . The remaining size of the parent can be divided into integer parts at will ,1+2、3+4、2+7 You can wait .
边栏推荐
- In depth analysis of kubebuilder
- The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
- B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
- [multi threading exercise] write a multi threading example of the producer consumer model.
- 架构实战训练营|课后作业|模块 6
- What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
- How to conduct website testing of software testing? Test strategy let's go!
- Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
- Network Security Learning - Information Collection
- Kivy tutorial of setting the size and background of the form (tutorial includes source code)
猜你喜欢
Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
How do test / development programmers get promoted? From nothing, from thin to thick
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
Windows are not cheap things
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
Basic idea of counting and sorting
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
随机推荐
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
MySQL forgot how to change the password
[untitled]
掌握软件安全测试方法秘笈,安全测试报告信手捏来
窗口可不是什么便宜的东西
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
Implementation of JSTL custom function library
Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!
leetcode 53. Maximum subarray maximum subarray sum (medium)
Win11图片打不开怎么办?Win11无法打开图片的修复方法
Advertising attribution: how to measure the value of buying volume?
树与图的深度优先遍历模版原理
Have you got the same "artifact" of cross architecture development praised by various industry leaders?
【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
True global ventures' newly established $146million follow-up fund was closed, of which the general partner subscribed $62million to invest in Web3 winners in the later stage
Network Security Learning - Information Collection
In depth analysis of kubebuilder
Two divs are on the same line, and the two divs do not wrap "recommended collection"
軟件測試之網站測試如何進行?測試小攻略走起!
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ