column-count

Baseline 已廣泛支援

此特性已得到良好確立,可跨多種裝置和瀏覽器版本使用。自 2017 年 3 月起,所有瀏覽器均支援此特性。

column-count CSS 屬性將元素內容拆分為指定數量的列。

試一試

column-count: 2;
column-count: 3;
column-count: 4;
column-count: auto;
column-width: 8rem;
<section id="default-example">
  <p id="example-element">
    London. Michaelmas term lately over, and the Lord Chancellor sitting in
    Lincoln's Inn Hall. Implacable November weather. As much mud in the streets
    as if the waters had but newly retired from the face of the earth, and it
    would not be wonderful to meet a Megalosaurus, forty feet long or so,
    waddling like an elephantine lizard up Holborn Hill.
  </p>
</section>
#example-element {
  width: 100%;
  text-align: left;
}

語法

css
/* Keyword value */
column-count: auto;

/* <integer> value */
column-count: 3;

/* Global values */
column-count: inherit;
column-count: initial;
column-count: revert;
column-count: revert-layer;
column-count: unset;

auto

列的數量由其他 CSS 屬性決定,例如 column-width

<integer>

一個嚴格正的 <integer>,描述了元素內容將流入的理想列數。如果 column-width 也被設定為非 auto 值,它僅表示允許的最大列數。

正式定義

初始值auto
應用於塊容器,除了表格包裝盒
繼承性
計算值同指定值
動畫型別一個整數

正式語法

column-count = 
auto |
<integer [1,∞]>

示例

將一個段落拆分為三列

HTML

html
<p class="content-box">
  This is a bunch of text split into three columns using the CSS
  <code>column-count</code>
  property. The text is equally distributed over the columns.
</p>

CSS

css
.content-box {
  column-count: 3;
}

結果

規範

規範
CSS Multi-column Layout Module Level 1
# cc

瀏覽器相容性

另見