CSS multi-column layout properties: column-count and column-gap

PHPz
Release: 2023-10-28 08:35:33
Original
1449 people have browsed it

CSS 多列布局属性:column-count 和 column-gap

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.

  1. column-count attribute

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:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Morbi sit amet urna leo. Suspendisse potenti.

Nunc dapibus vitae libero a tristique. Donec vitae commodo sem, eu tristique erat.

Fusce tristique lorem sed ipsum consectetur, nec laoreet dui euismod.

Maecenas eget sem id ex feugiat placerat. Sed nec enim placerat, tristique diam in, sollicitudin sapien.

Copy after login
Copy after login

CSS code:

.columns { column-count: 3; }
Copy after login

The above code will wrap the

element Paragraph text is displayed in 3 columns. The browser will automatically layout the content based on the length and number of columns to achieve multi-column display.

  1. column-gap attribute

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:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Morbi sit amet urna leo. Suspendisse potenti.

Nunc dapibus vitae libero a tristique. Donec vitae commodo sem, eu tristique erat.

Fusce tristique lorem sed ipsum consectetur, nec laoreet dui euismod.

Maecenas eget sem id ex feugiat placerat. Sed nec enim placerat, tristique diam in, sollicitudin sapien.

Copy after login
Copy after login

CSS code:

.columns { column-count: 3; column-gap: 20px; }
Copy after login

The above code will wrap the

element Paragraph text is displayed in 3 columns, with a 20-pixel spacing between each column.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!