CSS3多欄版面配置

來源:互聯網
上載者:User

在CSS3中,也新增了一些關於文本布局的幾個比較簡單的屬性。通過這些新增的屬性,我們可以對文本進行簡單的排版,就想報紙和雜誌那樣。

新增的部分屬性,以及瀏覽器支援情況:

屬性 瀏覽器支援
column-count IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera
column-gap IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera
column-rule IE Firefox(-moz-) Chrome(-webkit-) Safari(-webkit-) Opera

註:

  • 在Firefox瀏覽器中,要加(-moz-)首碼。
  • 在Chrome和Safari瀏覽器中,要加(-webkit-)首碼。
  • 對於IE瀏覽器,只支援IE10以及以上版本。

新增的屬性以及描述:

屬性 描述
column-count 定義元素應該被分隔的列數
column-fill 定義列的填充方式
column-gap 定義列之間的間隔距離
column-rule column-rule屬性的簡寫屬性,定義列之間的規則
column-rule-color 定義列之間的規則顏色
column-rule-style 定義列之間的規則樣式
column-rule-width 定義列之間的規則寬度
column-span 定義元素應該橫跨的列數
column-width 定義列的寬度
columns column-width 和 column-count 的簡寫屬性

通過這幾個新增屬性的定義,我可以對文本進行簡單的排版(Firefox瀏覽器)

*{-moz-column-count: 3;-moz-column-gap: 40px;-moz-column-rule: 4px outset #ff0000;"}

上面的CSS樣式是元素中的文本分為3列,列之間的距離為40px,列之間用顏色為#ff0000、寬度為4px的線分開。

同樣,我們也可以對一些元素中的內容進行排版。

例如我們可以對列表進行排版:

部分代碼為(Firefox瀏覽器):

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style>ul {    -moz-column-count: 3;    -moz-column-gap: 40px;    -moz-column-rule: 4px outset #ff0000;}li {    background: #0CF;    border: #069 1px solid;    display: inline-block;    width: 150px;    margin: 5px 0;}</style></head><body><ul>    <li style="height:50px">1</li>    <li style="height:100px">2</li>    <li style="height:80px">3</li>    <li style="height:60px">4</li>    <li style="height:70px">5</li>    <li style="height:50px">6</li>    <li style="height:100px">7</li>    <li style="height:80px">8</li>    <li style="height:90px">9</li>    <li style="height:30px">10</li></ul></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.