what is css masonry layout - Search
Open links in new tab
  1. Masonry layout is a popular web design technique for creating a visually appealing and space-efficient arrangement of elements with varying heights. It's akin to fitting stones in a wall, where the elements are laid out in such a way that gaps are minimized, creating a "masonry" effect.

    Implementing Masonry Layout with CSS Grid

    CSS Grid Layout's Level 3 specification introduces a masonry value for grid-template-columns and grid-template-rows, allowing for the creation of masonry layouts directly with CSS. Here's how you can implement a masonry layout using CSS Grid:

    container {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    grid-template-rows: masonry;
    }

    In this setup, the columns act as the strict grid axis, while the rows follow the masonry layout. Items are placed item by item along the rows, and as new rows are formed, the items adjust to fill the gaps left by shorter items above them.

    Controlling the Layout

    On the grid axis, standard grid layout rules apply. You can span items across multiple tracks using the span keyword or position them using line-based positioning. For the masonry axis, which follows different rules, you can use properties like masonry-auto-flow, align-tracks, and justify-tracks to control the behavior and alignment of items.

    Feedback
    Kizdar net | Kizdar net | Кыздар Нет