>父元素 display: flex; display: -webkit-flex;
flex-grow: 1; flex-grow: 1; 等比例缩放
align-items: stretch; 等高布局
flex属性
flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。
flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。
flex-basis属性定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小。
.item {
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<style type="text/css">
.box{
display: flex;
display: -webkit-flex;
background: #999;
}
.box span{
margin: 10px 10px;
padding: 10px;
background: #ff0;
width: 50px;
}
.box span:nth-of-type(1){
flex-grow: 1;
}
.box span:nth-of-type(2){
flex-grow: 3;
}
</style>
<div class="box">
<span>你好1</span>
<span>你好2</span>
<span>你好3</span>
<span>你好4</span>
<span>你好5</span>
</div>
</body>
</html>
参考网址:
https://blog.csdn.net/qq_34648000/article/details/79115294 属性讲解
https://blog.csdn.net/s8460049/article/details/54970868 案例直击
https://blog.csdn.net/linda_417/article/details/51507176 属性讲解 flex
等高布局
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<style type="text/css">
.box,.bx{
display: flex;
display: -webkit-flex;
/*换行*/
/*flex-wrap: wrap;*/
/*不换行,默认*/
/*flex-wrap: nowrap;*/
/*换行,第一行在下方*/
/*flex-wrap: wrap-reverse;*/
flex-wrap: nowrap;
background: #999;
width: 100%;
}
.bp{
display: flex;
display: -webkit-flex;
/*换行*/
/*flex-wrap: wrap;*/
/*不换行,默认*/
/*flex-wrap: nowrap;*/
/*换行,第一行在下方*/
/*flex-wrap: wrap-reverse;*/
flex-wrap: nowrap;
align-items: stretch;
background: #999;
width: 100%;
}
.box span,.bx span,.bp span{
margin: 10px 10px;
padding: 10px;
background: #ff0;
width: 50px;
}
.bp .sg{background: #D54E3B;
width: 50px;}
.sf,.sb{
background: #ff0;
margin: 10px 10px;
flex: 0 0 80px;
}
</style>
<div class="box">
<span>你好1</span>
<span>你好2</span>
<span>你好3</span>
<span>你好4</span>
<span>你好5</span>
<span>你好6</span>
<span>你好7</span>
</div>
<div class="bx">
<div class="sf">wewe</div>
<span>你好1</span>
</div>
<div class="bx">
<div class="sf">wewe</div>
<span>你好1</span>
</div>
<div class="bp">
<div class="sb">wewe</div>
<span>你好1</span>
</div>
</body>
</html>
网友评论