Home > Web Front-end > CSS Tutorial > Can CSS Create a Masonry Layout Without JavaScript?

Can CSS Create a Masonry Layout Without JavaScript?

Linda Hamilton
Release: 2024-12-04 15:02:12
Original
812 people have browsed it

Can CSS Create a Masonry Layout Without JavaScript?

Can CSS Alone Create a Masonry-Style Layout?

The masonry layout exhibits the following characteristics:

  • Boxes vary in height.
  • Some boxes are noticeably wider.

Can this layout be achieved solely through CSS?

CSS Approach

Indeed, it is feasible with CSS3 support:

.container {
    -moz-column-count: 2;
    -moz-column-gap: 10px;
    -webkit-column-count: 2;
    -webkit-column-gap: 10px;
    column-count: 2;
    column-gap: 10px;
    width: 360px;
}

.container div {
    display: inline-block;
    width: 100%;
    background-color: red;
}
Copy after login

Non-CSS3 Approach

Unfortunately, this layout requires JavaScript in the absence of CSS3 support.

The above is the detailed content of Can CSS Create a Masonry Layout Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template