English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS3 multi-column layout

Using CSS3, where you can divide the text content of an element into multiple columns.

Create multi-column layout

CSS3The multi-column layout module has been introduced to create multiple column layouts in a simple and effective way. Now, you can create layouts like those seen in magazines and newspapers without using float boxes. This is a layout using CSS3A simple example of the multi-column layout feature, which divides some text into three columns.

p {
    -webkit-column-count: 3; /* Chrome, Safari, Opera */
       -moz-column-count: 3; /* Firefox */
            column-count: 3; 
}
Test to see‹/›

sets the number of columns or width

CSS property, 'column'-count and 'column'-width specifies whether and how many columns will be displayed. 'column'-The 'count' attribute sets the number of columns within a 'multicol' element, while the 'column'-The 'width' attribute sets the required column width.

p {
    -webkit-column-width: 150px; /* Chrome, Safari, Opera */
       -moz-column-width: 150px; /* Firefox */
            column-width: 150px; 
}
Test to see‹/›

Note:column-The 'width' attribute specifies the optimal width for a column. However, the actual column width may vary in width or narrowness depending on the available space. This property should not be confused with the 'column'-count property together.

to set the column gap

You can use the column-The gap property specifies the space between columns. The same gap is applied between each column. The default gap is normal, which is equal to1em.

p {
    /* Chrome, Safari, Opera */
    -webkit-column-count: 3;
    -webkit-column-gap: 100px;
    /* Firefox */
    -moz-column-count: 3;
    -moz-column-gap: 100px;
    
    column-count: 3;
    column-gap: 100px;
}
Test to see‹/›

to set the column rule

You can also use column-The rule property adds a line, that is, a rule, between columns. It is a shorthand property used to set the width, style, and color of the rule in a single declaration. The column-The rule property takes the same values as border and outline.

p {
    /* Chrome, Safari, Opera */
    -webkit-column-count: 3;
    -webkit-column-gap: 100px;
    -webkit-column-rule: 2px solid red;
    /* Firefox */
    -moz-column-count: 3;
    -moz-column-gap: 100px;
    -moz-column-rule: 2px solid red;
    
    column-count: 3;
    column-gap: 100px;
    column-rule: 2px solid red;
}
Test to see‹/›

Note:The width of the column rule does not affect the width of the column box, but if the width of the column rule is greater than the gap, the adjacent column boxes will overlap with the rule.

CSS3Multi-column Properties

The following table briefly summarizes all multi-column properties:

PropertyDescription
column-countspecifies the number of columns within a multi-column element.
column-fillspecifies how content is distributed across columns.
column-gapspecifies the gap between columns.
column-rulespecifies the line or ruler to be drawn between columns.
column-rule-colorspecifies the color of the rule between columns.
column-rule-stylespecifies the rule style between columns.
column-rule-widthspecifies the rule width between columns.
column-spanspecifies how many columns an element spans.
column-widthat the same time.
columnsis used to setcolumn-widthandcolumn-countis a shorthand property for the properties.