CSS Multiple Columns
Users often find it difficult to read a sentence where the width of the line is big and they feel distracted to track the next line.
So, we can break the texts in a long line by using the CSS Multiple Columns layout which is often called as CSS multi-column layout. There are several properties of multi-column layout –
Multiple Column Count
The column-count property decides the count of the number of columns a particular element will be divided into.
The column-width property sets the width of the column.
column-width: auto| length-val| inherit;
auto – > Browser will automatically assign the optimal width
length-val – > You need to set the valid value of the column length
inherit -> It will get the width from its parent
To set the column-width and column-count, you can directly use the shorthand columns property.
Suppose, we code – columns: 150px 4;
This does not mean that the column-width and column-count will be exactly 150px and 4 respectively but what actually it says is – On an average screen device, the minimum width of the column should be 150px while the optimal number of columns can be maximum 4.
So, the width can be more than 150px as well and columns can be 4 depending on the device size. Similarly, for a very small device, if the browser does not find a minimum width of 150px, then it can reduce the width of the column as well and in that case, the number of columns can also shrink.
columns: column-width column-count| auto| inherit;
auto – > Browser will automatically assign the optimal column width and count
inherit -> It will get the column width and count from its parent
Using the column-gap property, you can control the space or gap between 2 consecutive columns.
column-gap: length-val| normal| inherit;
normal – > This is the default value
length-val– > Valid length for a gap
inherit – > The same property as that of parent
Column Rule Style
The column-rule-style is similar to the border-style property using which you can set the style of the column rule which is present between 2 continuous columns
column-rule-style: solid| dashed| dotted| double| ridged| groove| inset| outset| outline| hidden| none| inherit;
Column Rule Width
The column-rule-width is similar to border-width using which you can set the width of the column rule which is present between 2 continuous columns
column-rule-width: length-val|thin| medium| thick| none| inherit;
length-val -> a valid length value for column-rule
Column Rule Color
Similar to the border-color property, the column-rule-color sets the color of the column rule.
color-value -> a valid color value which can be a color name, hexadecimal value, RGB value etc.
If you do not code this, the browser automatically assigns the column-rule-color as black.
The column-rule is similar to border property where you can set the width of the column-rule, type of column-rule and color of the column-rule.
In short, it is the shorthand for column-rule-width, column-rule-style & column-rule-color.
column-rule: column-rule-width column-rule-style column-rule-color;
Using the column-span, we can control, if an element will span across all the columns or will not span at all.
By default, an element will not span across the columns.
column-span: all| none| inherit;
all -> This enables an element to span across all the columns
none ->Do not span across any column
inherit -> Use the same property as that of the parent
Let us take another scenario,where you want to set maximum text in each column, then you have a possibility of some/few columns being empty as well. This is possible using column-fill: auto.
column-fill: auto| balance| inherit;
auto -> Fill the content to the maximum area possible in each column even if few columns are empty
balance ->Balance out each column in order to try to fill all the columns. The idea is to try making all the columns as uniform and Non-empty. Of course, the last column can have less content
inherit -> Apply the same property as that of the parent