CSS columns Property

CSS columns Property

 

CSS columns Property


The CSS columns property is a shorthand for the following properties:

  • column-count, which defines the maximum number of columns.
  • column-width, which defines the minimum width of columns.

These two properties together create a multi-column layout which will automatically break down into a single column at narrow browser widths without the need for media queries or other rules.

The columns property is one of the CSS3 properties.

Setting both column-count and column-width is not always make sense, as it can restrict the flexibility and responsiveness of the layout.

If the width and count of columns do not fit into the width of the element, the browser will automatically reduce the column count to fit the specified column widths.

Initial Valueauto auto
Applies toBlock containers except for table wrapper boxes.
InheritedNo.
AnimatableYes. Width and count of columns are animatable.
VersionCSS3
DOM Syntaxobject.style.columns = "100px 2";

Syntax

columns: auto | column-width column-count | initial | inherit;

Example of the columns property: 

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .example {
        -webkit-columns: 100px 3;
        /* Chrome, Safari, Opera */
        -moz-columns: 100px 3;
        /* Firefox */
        columns: 100px 3;
      }
    </style>
  </head>
  <body>
    <h2>Columns property example</h2>
    <div class="example">
      Lorem Ipsum is dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into e lectronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
  </body>
</html>

Example of the columns property with specified width and number of columns: 

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .example {
        -webkit-columns: 50px 5;
        /* Chrome, Safari, Opera */
        -moz-columns: 50px 5;
        /* Firefox */
        columns: 50px 5;
      }
    </style>
  </head>
  <body>
    <h2>Columns property example</h2>
    <div class="example">
      Lorem Ipsum is dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </div>
  </body>
</html>

Values

ValueDescription
autoColumn-width and column-count properties are set to auto. This is the default value.
column-widthSets minimum width for columns.
column-countSets the maximum number of columns.
initialSets the property to its default value.
inheritInherits the property from its parent element.
Reactions

Post a Comment

0 Comments

close