Home >Web Front-end >CSS Tutorial >How to create a responsive list layout with dynamically adjusting columns using CSS3?

How to create a responsive list layout with dynamically adjusting columns using CSS3?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-12 06:06:011051browse

How to create a responsive list layout with dynamically adjusting columns using CSS3?

Displaying List Items in Columns using CSS3

Problem Statement:

Building a responsive layout requires displaying list items vertically, with the number of columns determined by the browser's width.

CSS3 Solution:

CSS3 columns provide an efficient solution for this layout:

#limheight {
    height: 300px; /* Define the container's height */
    -webkit-column-count: 3;
       -moz-column-count: 3;
            column-count: 3; /* Specify the desired number of columns */
}

#limheight li {
    display: inline-block; /* Ensure each list item is treated as a block element */
}

Example:

<ul>

When the browser window is wide enough, the list items will be displayed in three columns:

1  4  7
2  5  8
3  6  9

As the browser window narrows, the columns will dynamically adjust to maintain a visually appealing layout.

The above is the detailed content of How to create a responsive list layout with dynamically adjusting columns using CSS3?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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