css --- flex布局

來源:互聯網
上載者:User

標籤:nbsp   ems   ges   style   元素   any   elf   direct   alt   

Flex 是 Flexible Box 的縮寫,意為"彈性布局"。任何一個容器都可以指定為 Flex 布局。文法部分參考連結在文末給出一篇阮一峰大神的文章,講的非常詳細。

 

採用Flex布局的元素,稱為Flex容器(flex container),簡稱”容器”。它的所有子項目自動成為容器成員,稱為Flex項目(flex item),簡稱”項目”。

容器預設存在兩根軸:水平的主軸(main axis)和垂直的交叉軸(cross axis)。主軸的開始位置(與邊框的交叉點)叫做main start,結束位置叫做main end;交叉軸的開始位置叫做cross start,結束位置叫做cross end。

項目預設沿主軸排列。單個項目佔據的主軸空間叫做main size,佔據的交叉軸空間叫做cross size。

 

注意,設為 Flex 布局以後,子項目的float、clear和vertical-align屬性將失效。

在頁面配置上,使用盒子布局------flex.如所示,下面是一種簡易例子,並給出注釋:

 

代碼如下:

<!doctype html> <html><head>    <title>box</title>    <style>        .wrap{            display: -webkit-box;            display: -moz-box;            display: -ms-flexbox;            display: -webkit-flex;            display: flex;//必須,此時採用flex布局            -moz-box-orient: vertical;            -webkit-box-orient: vertical;//子項目縱向排列            -ms-box-orient: vertical;            -webkit-flex-direction: column;//主線為垂直            -ms-flex-direction: column;            flex-direction: column;        }        .lay{            width:150px;            height:150px;            border:1px solid red;            margin:10px;            padding:10px;        }        .box1 {            -webkit-box-ordinal-group: 1;            -moz-box-ordinal-group: 1;            -ms-flex-order: 1;            -webkit-order: 1;            order: 1;//定義項目的排列順序,數值越小,排列越靠前,預設為0        }        .box2 {            -webkit-box-ordinal-group: 3;            -moz-box-ordinal-group: 3;            -ms-flex-order: 3;            -webkit-order: 3;            order: 3;        }        .box3{            -webkit-box-ordinal-group: 2;            -moz-box-ordinal-group: 2;            -ms-flex-order: 2;            -webkit-order: 2;            order: 2;
            align-self: flex-start;//允許單個項目有與其他項目不一樣的對齊,可覆蓋align-items屬性。
預設值為auto,表示繼承父元素的align-items屬性
            width:90%;
} </style></head><body><div class="wrap"> <div class="box1 lay"> this is box 1 </div> <div class="box2 lay"> this is box 2 </div> <div class="box3 lay"> this is box 3 </div></div></body></html>

 

 

 

參考:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool   Flex布局教程:文法篇

 

css --- flex布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.