Languages
[Edit]
EN

CSS - grid with 4 elements per row using flexbox (keeping the same items size)

0 points
Created by:
Inayah-Alexander
767

In this article, we would like to show you how to create grid with 4 elements per row using flexbox in CSS.

In the examples below, we create spacer elements that are invisible at the end of our grid. Spacer and child elements use flex property to occupy the same amount of space (25% - margins + paddings + borders of the element). To create grid with columns_count elements per row add columns_count - 1 spacer elements at the end.

Practical examples

Edit

Example 1

Edit

Example 2

Edit

 

See also

Edit
  1. CSS - grid with 3 elements per row using flexbox (keeping the same items size)

  2. CSS - grid with 5 elements per row using flexbox (keeping the same items size)

References

Edit
  1. flex - CSS: Cascading Style Sheets | MDN
  2. Flexbox - Learn web development | MDN
  3. calc() - CSS: Cascading Style Sheets | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join