flex:1
flex:1是三个属性的缩写。
flex-grow:1;
flex-shrink:1;
flex-basis:auto;
如果有两列div:
.left{
flex:2;/*占比2/3*/
}
.right{
flex:1;/*占比1/3*/
}
width遇到flex-basis无效
flex-basis是基准宽度的意思,默认为auto,也就是自动计算数值,但如果有具体数值,则按照这个数值进行宽度设置,即使写了width也是无效的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.flex {
display:flex;
}
.box{
width:100%;
height:500px;
}
.left{
width:500px;/*遇到flex-basis无效*/
flex-grow:1;
flex-shrink: 1;
flex-basis: 50%;
/* flex:50%; */
background:red;
}
.right{
width:300px;/*遇到flex-basis无效*/
flex:30%;/*可简写*/
background:yellow;
}
</style>
</head>
<body>
<div class="box flex">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
网友评论