CSS的box-align屬性控制子項目布局執行個體分析

來源:互聯網
上載者:User
box-align 說明

box-align屬性, 指定元素內子要素縱方向排列指定時使用。<規定框中子項目的顯示次序。>
容器元素比子項目大很多的情況下,使用box-align屬性,可以指定子項目的排序次序,並且可以指定子項目如何表示。
還有,縱方向排列一說,可以解釋為元素內子項目的配置方向預設值為水平,使用此屬性後垂直方向進行排列。也可以使用 box-orient:vertical來設定子項目排列方向。

屬性值
start:標準方向元素,各子要素上端沿著元素上端進行排列,餘下的位置向下排序, 反方向元素的話,則沿著下端進行排序,餘下的位置向上排序。<對於正常方向的框,每個子項目的上邊緣沿著框的頂邊放置。 對於反方向的框,每個子項目的下邊緣沿著框的底邊放置。>
end:標準方向元素,各子要素下端沿著元素下端進行排列,餘下的位置向上排序, 反方向元素的話,則沿著上端進行排序,餘下的位置向下排序。<對於正常方向的框,每個子項目的下邊緣沿著框的底邊放置。 對於反方向的框,每個子項目的上邊緣沿著框的頂邊放置。>
center:剩餘空間,進行均等分配。<均等地分割多餘的空間,一半位於子項目之上,另一半位於子項目之下。>
baseline:inline-axis和horizontal的場合,所有子項目baseline配置排列<如果 box-orient 是inline-axis或horizontal,所有子項目均與其基準對齊。>
stretch:各子項目按照容器元素的高來自動排序(預設值)

關於置中
原來水平垂直置中寫法為:height=line-height 實現垂直置中text-align實現水平置中
現在使用box-align實現垂直置中box-pack 實現水平置中

<!DOCTYPE html>   <html>   <head>       <title>水平及垂直置中</title>   </head>   <body >   <p style="width:300px; height: 300px; background-color: #ccc;  line-height: 300px; text-align: center;">       <input type="button" value="原有置中方式">   </p>   <p style="width:300px; height: 300px; background-color: #aaa; display:-webkit-box;-webkit-box-pack: center;   ; -webkit-box-align:center">       <input type="button" value="css3的置中方式">   </p>   </body>   </html>

執行個體代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <title> box-align </title>   <style>   p.prefix_sample1 {   width:500px; height:100px;   background-color:yellow;   display:-moz-box;   display:-webkit-box;   display:-o-box;   display:-ms-box;   -moz-box-align:start;   -webkit-box-align:start;   -o-box-align:start;   -ms-box-align:start;   }   p.prefix_sample2 {   width:500px; height:100px;   background-color:yellow;   display:-moz-box;   display:-webkit-box;   display:-o-box;   display:-ms-box;   -moz-box-align:end;   -webkit-box-align:end;   -o-box-align:end;   -ms-box-align:end;   }   p.prefix_sample3 {   width:500px; height:100px;   background-color:yellow;   display:-moz-box;   display:-webkit-box;   display:-o-box;   display:-ms-box;   -moz-box-align:center;   -webkit-box-align:center;   -o-box-align:center;   -ms-box-align:center;   }   p.prefix_sample4 {   width:500px; height:100px;   background-color:yellow;   display:-moz-box;   display:-webkit-box;   display:-o-box;   display:-ms-box;   -moz-box-align:baselinebaseline;   -webkit-box-align:baselinebaseline;   -o-box-align:baselinebaseline;   -ms-box-align:baselinebaseline;   }   p.prefix_sample5 {   width:500px; height:100px;   background-color:yellow;   display:-moz-box;   display:-webkit-box;   display:-o-box;   display:-ms-box;   -moz-box-align:stretch;   -webkit-box-align:stretch;   -o-box-align:stretch;   -ms-box-align:stretch;   }   p.aka {background-color:red;}   p.midori {background-color:green;}   p.ao {background-color:blue;}   </style>   </head>   <body>   <h4>box-align:start;</h4>   <p class="prefix_sample1">   <p class="aka">abcde</p>   <p class="midori">abcde</p>   <p class="ao">abcde</p>   </p>   <h4>box-align:end;</h4>   <p class="prefix_sample2">   <p class="aka">abcde</p>   <p class="midori">abcde</p>   <p class="ao">abcde</p>   </p>   <h4>box-align:center; </h4>   <p class="prefix_sample3">   <p class="aka">abcde</p>   <p class="midori">abcde</p>   <p class="ao">abcde</p>   </p>   <h4>box-align:baselinebaseline; </h4>   <p class="prefix_sample4">   <p class="aka">abcde</p>   <p class="midori">abcde</p>   <p class="ao">abcde</p>   </p>   <h4>box-align:stretch; </h4>   <p class="prefix_sample5">   <p class="aka">abcde</p>   <p class="midori">abcde</p>   <p class="ao">abcde</p>   </p>   </body>   </html>

執行個體圖

聯繫我們

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