当前位置:网站首页>Flex layout
Flex layout
2022-07-24 06:29:00 【PS notes】
Flex Layout
Elastic box layout
Basic concepts : First set the element to display:flex; The element becomes a flex Containers
The elements inside the container are flex Element or flex project (flex-item)
I learned before :Display:none Set element hide
Display:block; Can be converted into block elements
Display:inline; Set to inline elements
<style> .container { display: flex; background-color: yellow; width: 800px; height: 300px; } .item{ width: 100px; /* height: 100px; */ background-color: red; border: 1px solid blue; } </style> <body> <div class="container"> <div class="item">123</div> <div class="item">456</div> <div class="item">789</div> </div> </body> </html>

Main axis: Spindle
Cross axis: Cross shaft
Default :
Flex The project in flex The container is arranged along the main axis
Flex The project is highly adaptable flex Container height ( Intra peer elements )
Set up flex Containers :
Flex-direction: Set up flex Item arrangement direction
Jusrif-content: flex Arrangement of project spindles
Align-items: flex Arrangement of project cross axes
Flex-direction:
Row( The default value is ): The principal axis is horizontal , The starting point is on the left
Row-reverse: The principal axis is horizontal , The starting point is on the right
Column: The principal axis is perpendicular , The starting point is at the top
Column-reverse: The principal axis is perpendicular , Starting edge
<style>
.container {
display: flex;
/* flex-direction: column; Horizontal to the upper left */
/* flex-direction:column-reverse; Horizontal to the bottom left */
/* flex-direction: row; Left longitudinal axis */
/* flex-direction: row-reverse; To the right longitudinal axis */
background-color: yellow;
width: 800px;
height: 300px;
}
.item{
width: 100px;
/* height: 100px; */
background-color: red;
border: 1px solid blue;
}
</style>
<body>
<div class="container">
<div class="item">123</div>
<div class="item">456</div>
<div class="item">789</div>
</div>
</body>
</html>


Justif-content: 、 Mainly used for control flex Alignment effect .
flex-start( Default ): Align left
flex-end: Right alignment
center: In the middle
space-between: full-justified , The gap between items is equal
space-around: The spacing between each item is equal , So the interval between items is twice as large as that between items and borders .
<style>
.container {
display: flex;
background-color: yellow;
width: 800px;
height: 300px;
justify-content: flex-start;
/* justify-content: flex-end; */
/* justify-content: center; */
/* justify-content: space-between; */
/* justify-content: space-around; */
}
.item{
width: 100px;
/* height: 100px; */
background-color: red;
border: 1px solid blue;
}
</style>
<body>
<div class="container">
<div class="item">123</div>
<div class="item">456</div>
<div class="item">789</div>
</div>
</body>
</html>




Align-items:
flex-start: Align the starting points of the intersecting axes ;
flex-end: The ends of the intersecting axes are aligned :
center: Align the midpoint of the intersecting axis ;
stretch:( extend )( The default value is ): If the project is not set to height or set to auto, Will fill the entire container .
<style> .container { display: flex; background-color: yellow; width: 800px; height: 300px; justify-content: flex-start; justify-content: space-between; /* align-items: flex-start; */ /* align-items: flex-end; */ /* align-items: center; */ align-items: stretch; } .item{ width: 100px; /* height: 100px; */ background-color: red; border: 1px solid blue; } </style> <body> <div class="container"> <div class="item">123</div> <div class="item">456</div> <div class="item">789</div> <div class="item">123</div> <div class="item">111</div> <div class="item">222</div> </div> </body> </html>




flex project :
flex-grow: Attribute defines the magnification of the item , Default 0, There's plenty of space , Equal proportion completion .
flex-shrink: It defines the reduction ratio of the project , Default 1, That is, if there is not enough space , The project will shrink
flex-basis: The spindles are arranged in width , The cross axes are arranged in height , Set up px, The default value is auto.
flex: Combine the above three styles .flex: 0 1 auto ;
align-self:flex The way of the project (auto、flex-start 、 flex-end 、center 、 baseline 、 stretch)
<style>
.container {
display: flex;
background-color: yellow;
width: 800px;
height: 300px;
}
.item{
background-color: red;
border: 1px solid blue;
flex-grow: 1;
}
.big{
flex-grow: 3;
}
</style>
<body>
<div class="container">
<div class="item">123</div>
<div class="item">456</div>
<div class="item big">789</div>
<div class="item">123</div>
<div class="item">111</div>
<div class="item">222</div>
</div>
</body>
</html>
.big{
width: 300px;
/* If the whole flex Projects are all scaled down , that flex-shrink The greater the value of , The more it shrinks , The smaller it is , I don't know much about it */
flex-shrink: 2;
}

.big{
/* flex-basis The function of is to set the width when the spindle is arranged 600px, I don't often know */
flex-basis:600px;
}

<style>
.container {
display: flex;
background-color: yellow;
width: 800px;
height: 300px;
}
.item{
background-color: red;
border: 1px solid blue;
/* Set the default value */
/* flex: 0 1 auto ; */ Add here ,0 yes flex-grow、1 yes flex-shrink、auto yes flex-basis It means .
/* flex-shrink: 2; You can abbreviate : */
flex:1;
}
.big{
/* flex-basis:600px; You can abbreviate : */
flex:2;
}
</style>
<body>
<div class="container">
<div class="item">123</div>
<div class="item">456</div>
<div class="item big">789</div>
<div class="item">123</div>
<div class="item">111</div>
<div class="item">222</div>
</div>
</body>
</html>Case study : Set an element vertically and horizontally centered in the container :
<style>
*{
margin: 0px;
padding: 0px;
}
body,html{
height: 100%;
}
.container {
background-color: yellow;
height: 100%;
display:flex;
justify-content: center;
/* align-items: center; Horizontal center */
}
.box{
width: 100px;
height: 100px;
background-color: blue;
/* align-self: center;=align-items: center; Horizontal center */
align-self: center;
}
</style>
<body>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
The bottom menu of the web page on the right side of the case production :
</head>
<style>
*{
margin: 0px;
padding: 0px;
}
.menu{
position: fixed;
background-color: yellow;
bottom: 0px;
display: flex;
width:100%;
height: 70px;
align-items: center;
}
.sub{
flex:1;
text-align: center;
}
.sub img{
height: 30px;
}
</style>
<body>
<div class="menu">
<div class="sub">
<img src="images/open.png" alt="">
<p> home page </p>
</div>
<div class="sub">
<img src="images/error.png" alt="">
<p> home page </p>
</div>
<div class="sub">
<img src="images/success.png" alt="">
<p> home page </p>
</div>
<div class="sub">
<img src="images/open.png" alt="">
<p> home page </p>
</div>
<div class="sub">
<img src="images/close.png" alt="">
<p> home page </p>
</div>
</div>
</body>
</html>
边栏推荐
- 【222】内存溢出及定位
- Metersphere one stop open source continuous testing platform
- Leetcode does not add, subtract, multiply, divide, and calculate the number of 1 in binary
- Flink function (1): rich function
- Public access intranet IIS website server [no public IP required]
- leetcode剑指offer jz5 替换空格字符串
- API流程和代码结构
- Top 10 vulnerability assessment and penetration testing tools
- Leetcode refers to the duplicate number in the offer jz3 array
- MySQL从基础到入门到高可用
猜你喜欢
随机推荐
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
IP job (1)
Flink function (2): checkpointedfunction
leetcode剑指offer JZ42 连续子数组的最大和
【218】CS架构和BS架构以及数据放在服务端和客户端的利与弊?
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
How to build a website full of ritual sense and publish it on the public website 2-2
Understanding of Flink parallelism
Map the intranet to the public network [no public IP required]
IP notes (9)
IP lesson summary (3)
Work summary of a test Manager / Test Supervisor / test director
IP notes (12)
leetcode 不用加减乘除算加法 || 二进制中1的个数
Leetcode refers to the duplicate number in the offer jz3 array
Remember to get the password of college student account once, from scratch
SSH远程访问及控制
LVM与磁盘配额
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
sed命令









