CSS - column-width Property



The CSS property column-width is responsible for setting the width of a column in a multiple-column layout. This makes the container having as many columns as can fit in the space, with each column maintaining the column-width value specified. In case the container's width is smaller than the column-width value specified, the width of the column will be smaller than the value that is given.

column-width property is used to create responsive layouts that fit in all the different screen sizes. column-count property always takes precedence over the column-width property.

Possible values

The CSS property column-width takes one of the following values:

  • auto: Width of column to be determined by other CSS property, column-count.

  • <length>: A positive integer value only. Negative or percentage values are invalid. Specifies the column's width. The actual column width may be different as it fills the available space.

Applies to

All the block containers except the table wrapper boxes.

Syntax

column-width = auto | <integer>

CSS column-width - <length> (In Pixels)

In the following example the content of a <p> element is splitted into columns based on the column-width value in pixels:

<html>
<head>
<style> 
   .col-count-width {
      column-width: 250px;
   }
</style>
</head>
<body>
   <h1>column -  Property</h1>

   <div>
      <p class="col-count-width">
      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. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.
   </p>
   </div>
</body>
</html>

CSS column-width - <length> (In Inches)

In the following example the content of a <p> element is splitted into columns based on the column-width value in inches:

<html>
<head>
<style> 
   .col-count-width {
      column-width: 2in;
   }
</style>
</head>
<body>
   <h1>column-width Property</h1>

   <div>
      <p class="col-count-width">
      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. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.
   </p>
   </div>
</body>
</html>
Advertisements