CSS3控制元素排列

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   2014   art   ar   

需求:

將改變為。

代碼:
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>AB換位置</title>    <style>    * {        margin: 0;        padding: 0;    }    .box {        width: 400px;        height: 500px;        margin: 50px auto;        border: 1px solid #999;        line-height: 200px;        font-size: 60px;        color: #fff;        text-align: center;        display: -webkit-box;        -webkit-box-orient: vertical;        -webkit-box-align: center;        -webkit-box-pack: center;        /*-webkit-box-direction: normal;*/        -webkit-box-direction: reverse;    }    .a {        width: 200px;        height: 200px;        background: red;    }    .b {        width: 200px;        height: 200px;        background: green;    }    </style></head><body>    <div class="box">        <div class="a">aaa</div>        <div class="b">bbb</div>    </div></body></html>
解釋:

1. display: -webkit-box; CSS3新盒模型,與display:flex;相似,具體請見。。。。

2. -webkit-box-orient: vertical; 子項目排列方向:縱向(vertical),還有橫向(horizontal,預設方向)。

3. -webkit-box-align: center; 子項目橫向相片順序:置中排列(center),還有靠左(start)、靠右(end)、靠基準(baseline)。

4. -webkit-box-pack: center; 子項目縱向相片順序:置中排列(center),還有靠上(start)、靠下(end)。

5. -webkit-box-direction: reverse; 子項目排列順序:倒序排列(reverse),還有正常(normal,預設順序)。

收穫:

通過一些CSS2的巧妙運用,也可以達到反序的效果,但只限兩個元素,如果元素個數大於2,再用CSS2反序,想死的心都有了。

不過CSS3這個direction還是很方便的,雖說有相容問題,單相信在不久的將來,CSS3就會變得更加常用和重要。

畢竟,“簡單,強大”才是主線。

 

聯繫我們

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