当前位置:网站首页>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 .
边栏推荐
- Nanopineo use development process record
- Gpt-3 is a peer review online when it has been submitted for its own research
- 计数排序基础思路
- DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
- 案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
- In depth analysis of kubebuilder
- This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
- [on automation experience] the growth path of automated testing
- Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
- Win11 control panel shortcut key win11 multiple methods to open the control panel
猜你喜欢
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
A detailed explanation of head pose estimation [collect good articles]
acwing 843. N-queen problem
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
Intel David tuhy: the reason for the success of Intel aoten Technology
AI 落地新题型 RPA + AI =?
NFT meta universe chain diversified ecosystem development case
随机推荐
Win11控制面板快捷键 Win11打开控制面板的多种方法
两个div在同一行,两个div不换行「建议收藏」
论文上岸攻略 | 如何快速入门学术论文写作
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
英特尔与信步科技共同打造机器视觉开发套件,协力推动工业智能化转型
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
用CPU方案打破内存墙?学PayPal堆傲腾扩容量,漏查欺诈交易量可降至1/30
C # use Siemens S7 protocol to read and write PLC DB block
[team learning] [34 issues] scratch (Level 2)
Master the secrets of software security testing methods, and pinch the security test report with your hands
程序员上班摸鱼,这么玩才高端!
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
Jetson nano配置pytorch深度学习环境//待完善
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
Nanopineo use development process record
Digital chemical plants realize the coexistence of advantages of high quality, low cost and fast efficiency
掌握软件安全测试方法秘笈,安全测试报告信手捏来
深入解析Kubebuilder