A grid is a set of intersectiong horizontal and vertical lines defining columns and row, and elements can be placed onto this grid within the column and row lines. Together with flxbox, grid is a powerful way to create an intricate CSS layout.
Features:
px
%
and fr
display: grid
display: inline-grid
An element is made into a grid container by display: grid
or inline-grid
declaration. All of its direct children become the grid items.
The default grid is to arrange the grid items vertically (1 column, multiple rows) just like in an unstyled list.
<!-- HTML --> <div class="gridDefault"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> <div>Item 4</div> <div>Item 5</div> </div>
/* CSS */ .gridDefault { display: grid; border: 4px solid plum; } .gridDefault div { border: 4px solid peachpuff; }
ResultItem 1Item 2Item 3Item 4Item 5