試一試
flex-wrap: nowrap;
flex-wrap: wrap;
flex-wrap: wrap-reverse;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
<div>Item One</div>
<div>Item Two</div>
<div>Item Three</div>
<div>Item Four</div>
<div>Item Five</div>
<div>Item Six</div>
</div>
</section>
#example-element {
border: 1px solid #c5c5c5;
width: 80%;
display: flex;
}
#example-element > div {
background-color: rgb(0 0 255 / 0.2);
border: 3px solid blue;
width: 60px;
margin: 10px;
}
flex-flow 簡寫屬性可用於同時設定 flex-direction 和 flex-wrap 屬性,它們分別定義彈性容器的主軸和側軸。
語法
css
flex-wrap: nowrap; /* Default value */
flex-wrap: wrap;
flex-wrap: wrap-reverse;
/* Global values */
flex-wrap: inherit;
flex-wrap: initial;
flex-wrap: revert;
flex-wrap: revert-layer;
flex-wrap: unset;
值
flex-wrap 屬性指定為以下值中的單個關鍵詞
nowrap-
彈性專案排布在單行上,這可能會導致彈性容器溢位。交叉起始點等同於 inline-start 或 block-start,具體取決於
flex-direction的值。這是預設值。 wrap-
彈性專案換行顯示在多行上。交叉起始點等同於 inline-start 或 block-start,具體取決於當前的 書寫模式 和
flex-direction的值。 wrap-reverse-
行為與
wrap相同,但交叉起始點和交叉結束點是反向的。
正式定義
正式語法
flex-wrap =
nowrap |
wrap |
wrap-reverse
示例
設定彈性容器換行值
HTML
html
<h4>This is an example for flex-wrap:wrap</h4>
<div class="content">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:nowrap</h4>
<div class="content1">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:wrap-reverse</h4>
<div class="content2">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
CSS
css
/* Common Styles */
.content,
.content1,
.content2 {
color: white;
font: 100 24px/100px sans-serif;
height: 150px;
width: 897px;
text-align: center;
}
.content div,
.content1 div,
.content2 div {
height: 50%;
width: 300px;
}
.red {
background: orangered;
}
.green {
background: yellowgreen;
}
.blue {
background: steelblue;
}
/* Flexbox Styles */
.content {
display: flex;
flex-wrap: wrap;
}
.content1 {
display: flex;
flex-wrap: nowrap;
}
.content2 {
display: flex;
flex-wrap: wrap-reverse;
}
結果
規範
| 規範 |
|---|
| CSS 彈性盒子佈局模組第 1 級 # flex-wrap-屬性 |
瀏覽器相容性
載入中…