CSS multi-column layout properties: column-count and column-gap, specific code examples are required
In front-end development, implementing multi-column layout is a very common requirement . In CSS, there are two properties that can help us easily implement multi-column layout, they are column-count and column-gap.
column-count attribute is used to specify how many columns the content of an element is divided into. It accepts a positive integer value indicating how many columns to divide the content into. It is worth noting that when the column-count attribute is set, the browser will automatically help us calculate and layout the number of columns.
The following is an example:
HTML code:
<div class="columns"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>Morbi sit amet urna leo. Suspendisse potenti.</p> <p>Nunc dapibus vitae libero a tristique. Donec vitae commodo sem, eu tristique erat.</p> <p>Fusce tristique lorem sed ipsum consectetur, nec laoreet dui euismod.</p> <p>Maecenas eget sem id ex feugiat placerat. Sed nec enim placerat, tristique diam in, sollicitudin sapien.</p> </div>
CSS code:
.columns { column-count: 3; }
The above code will wrap the
column-gap attribute is used to specify the distance between columns. It accepts a length value that represents the spacing between columns. We can use pixel values, percentages or keywords to set the corresponding distance.
The following is an example:
HTML code:
<div class="columns"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>Morbi sit amet urna leo. Suspendisse potenti.</p> <p>Nunc dapibus vitae libero a tristique. Donec vitae commodo sem, eu tristique erat.</p> <p>Fusce tristique lorem sed ipsum consectetur, nec laoreet dui euismod.</p> <p>Maecenas eget sem id ex feugiat placerat. Sed nec enim placerat, tristique diam in, sollicitudin sapien.</p> </div>
CSS code:
.columns { column-count: 3; column-gap: 20px; }
The above code will wrap the
Summary:
By using the column-count and column-gap attributes, we can easily implement multi-column layout. column-count is used to specify how many columns the content is divided into, and column-gap is used to specify the distance between columns. These two attributes can quickly help us achieve multi-column layout effects and have good controllability.
The above is an introduction to the CSS multi-column layout properties column-count and column-gap. I hope it will be helpful to you. Everyone is welcome to try to use these properties in actual projects to achieve better layout effects.
The above is the detailed content of CSS multi-column layout properties: column-count and column-gap. For more information, please follow other related articles on the PHP Chinese website!