
批改狀態(tài):合格
老師批語:
使用flex布局,先設(shè)置容器為flex容器,容器的子元素自動變?yōu)槿萜鞯捻椖?,且為行?nèi)塊級元素
<style>
.container {
/* 轉(zhuǎn)為flex布局,該元素即為flex容器 */
display: flex;
height: 20rem;
}
</style>
---------------------------------------------------------------
<body>
<div class="container">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
<div class="item">item5</div>
<div class="item">item6</div>
<div class="item">item7</div>
<div class="item">item8</div>
</div>
</body>
.container {
/* 主軸方向: 默認水平 */
/* flex-direction: row; */
/* 禁止換行 */
/* flex-wrap: nowrap; */
/* 簡化寫法 */
flex-flow: row nowrap;
}
.container {
/* 允許換行 */
/* flex-flow: row wrap; */
/* 垂直換行 */
flex-flow: column wrap;
}
方式 1: 所有項目作為整體處理
flex-start
flex-end
center
方式 2:項目作為個體處理
space-between
space-around
space-evenly
方式 1: align-items
設(shè)置flex子項在每個flex行的交叉軸上的默認對齊方式
align-items: stretch
align-items: flex-start
align-items: flex-end
align-items: center
方式 2:align-content
適用多行的flex容器(也就是flex容器中的子項不止一行時該屬性才有效果),它的作用是當(dāng)flex容器在交叉軸上有多余的空間時,將子項作為一個整體(屬性值為:flex-start、flex-end、center時)進行對齊
align-content: stretch
align-content: flex-start
align-content: flex-end
align-content: center
align-content: space-between
align-content: space-around
align-content: space-evenly
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號