1. A largura dos lados esquerdo e direito é fixada em 100px e a largura do meio é adaptável de acordo com a largura da tela
.
<div class="main">
<div class="box1">
左侧
</div>
<div class="box2">
中间
</div>
<div class="box3">
右侧
</div>
</div>
.main {
/* 占父盒子宽度的100% */
width: 100%;
height: 40px;
background: #999;
/* 父盒子设置flex */
display: flex;
color: #fff;
line-height: 40px;
text-align: center;
}
.main .box1,
.main .box3 {
/* box1,box3固定宽度 */
width: 100px;
height: 40px;
background: pink;
}
.main .box2 {
/* box2占据剩余宽度 */
flex: 1;
height: 100%;
background: blue;
}
2. A caixa filho é centralizada horizontalmente e verticalmente na caixa pai ( outras formas )
:
<div class="box">
<div class="childrenBox">
</div>
</div>
.box {
width: 400px;
height: 400px;
background: #666;
/* 父级设置flex */
display: flex;
/* 设置主轴上的子元素排列方式:居中 */
justify-content: center;
/* 设置侧轴上的子元素排列方式:居中(单行) */
align-items: center;
border-radius: 10px;
}
.childrenBox {
width: 100px;
height: 100px;
background: #999;
}
3. A caixa-pai tem uma largura de 500 e uma altura de 400. Existem 6 caixas-filho na caixa-pai com uma largura e altura de 150 * 150. As caixas-filho são exibidas em duas linhas em três linhas, e à esquerda e o espaçamento direito das caixas filho são iguais, e os espaçamentos superior e inferior são iguais
alcançar:
<ul class="box">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
.box {
width: 500px;
height: 400px;
padding: 0;
background: #ccc;
display: flex;
list-style: none;
display: flex;
/* 换行显示 */
flex-wrap: wrap;
/* 设置主轴 间距平均分配 */
justify-content: space-around;
/* 设置侧轴 间距平均分配(子项多行显示的情况) */
align-content: space-around;
}
.box li {
width: 150px;
height: 150px;
background: pink;
}```