[ css 彈性盒子模型 align-content align-items屬性 ] 彈性盒子模型flex布局中align-items 和align-content屬性講解及執行個體示範的區別

來源:互聯網
上載者:User

標籤:

align-items

  align-items屬性適用於所有的flex容器,它是用來設定每個flex元素在側軸上的預設對齊,還有一位回答者的回答也很好,如下:

    align-items和align-content有相同的功能,不過不同點是它是用來讓每一個單行的容器置中而不是讓整個容器置中

align-content

  align-content屬性只適用於多行的flex容器,並且當側軸上有多餘空間使flex容器內的flex線對齊,感覺這樣翻譯了之後還是略微有些抽象,不過有一個重點就是多行, 
下面我們來寫一個小的例子。

<div class="child-1">    <div class="child-2"> </div>    <div class="child-2"> </div></div>

html結構如上。 
如果child-1的width設定為100px,child-2的width設定為30px,這樣child-2會排列在一排上,具體的css如下

<style type="text/css">* {    margin: 0px;    padding: 0px;}div {    border: 1px solid #0f0f0f;}.child-1 {    margin: 30px auto;    display: flex;    width: 100px;    height: 60px;    justify-content: space-around;    align-content: center;}.child-2 {    width: 30px;    height: 20px;}</style>

 

最終的結果如 

所以對於只有一行的flex元素,align-content是沒有效果的,如果.child-1改用align-items:center;則會達到預期的效果,如 

但如果變成多行容器 
使用align-items時效果如下 
 
使用align-content效果如下 

[ css 彈性盒子模型 align-content align-items屬性 ] 彈性盒子模型flex布局中align-items 和align-content屬性講解及執行個體示範的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.