column-count
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
Thuộc tính column-count CSS chia nội dung của phần tử thành số cột được chỉ định.
Thuộc tính viết tắt columns có thể được dùng để đặt các giá trị thuộc tính column-count, column-height và column-width trong một khai báo duy nhất.
Try it
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;
}
Cú pháp
css
/* Giá trị từ khóa */
column-count: auto;
/* Giá trị <integer> */
column-count: 3;
/* Giá trị toàn cục */
column-count: inherit;
column-count: initial;
column-count: revert;
column-count: revert-layer;
column-count: unset;
Giá trị
auto-
Số cột được xác định bởi các thuộc tính CSS khác, chẳng hạn như
column-width. <integer>-
Là một
<integer>dương nghiêm ngặt mô tả số cột lý tưởng mà nội dung của phần tử sẽ được phân bố vào. Nếucolumn-widthcũng được đặt thành giá trị khácauto, nó chỉ chỉ ra số cột tối đa được phép.
Định nghĩa hình thức
| Initial value | auto |
|---|---|
| Applies to | Block containers except table wrapper boxes |
| Inherited | no |
| Computed value | as specified |
| Animation type | an integer |
Cú pháp hình thức
column-count =
auto |
<integer [1,∞]>
<integer> =
<number-token>
Ví dụ
>Chia một đoạn văn thành ba cột
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;
}
Kết quả
Đặc tả
| Specification |
|---|
| CSS Multi-column Layout Module Level 1> # cc> |
Tương thích trình duyệt
Xem thêm
column-heightcolumn-width- Thuộc tính viết tắt
columns column-rule-color,column-rule-style,column-rule-width, thuộc tính viết tắtcolumn-rule- Tìm hiểu: Bố cục nhiều cột (Tìm hiểu Bố cục)
- Khái niệm cơ bản về Multicol