Categories
Web development

CSS Columns property

CSS Columns property

The CSS columns property is a shorthand property for:

CSS column-width property

CSS column-count property

Syntax:

columns: auto|column-width column-count;

auto (default) – sets both the column-width and column-count to “auto”.

column-width – specifies the minimum width for each column.

column-count – specifies the maximum number of columns.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
.text {
  columns: 100px 3;
}

</style>
</head>
<body>

<div class="text">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 
</div>

</body>
</html>

Output:

Set the minimum width for each column to 100px, and the maximum number of columns to 3:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Enjoy coding!