⊗mkSpRsTG 127 of 128 menu

Responsive Tile with Gap in CSS

Now let's make a tile with indents. Here's an example of what we should get:

First, let's create styles for the parent blocks:

.parent { display: flex; flex-wrap: wrap; width: 95%; margin: 50px auto; }

Since our grid is 3 by 3, there will be no such fourth row and column in this grid. But they will not be in explicit form, that is, in the form we set. But the browser will create them implicit, that is, itself.

.child { box-sizing: border-box; height: 100px; padding: 20px; margin-bottom: 1.5%; border: 1px solid green; }

Now let's write some code that will put four blocks in a row, setting the appropriate indents:

@media (min-width: 1000px) { .child { width: calc(100% / 4 - 1.5% * 3 / 4); } .child:not(:nth-child(4n)) { margin-right: 1.5%; } }

Now let's put three blocks in a row:

@media (min-width: 700px) and (max-width: 1000px) { .child { width: calc(100% / 3 - 1.5% * 2 / 3); } .child:not(:nth-child(3n)) { margin-right: 1.5%; } }

Now let's put two blocks in a row:

@media (min-width: 400px) and (max-width: 700px) { .child { width: calc(100% / 2 - 1.5% * 1 / 2); } .child:not(:nth-child(2n)) { margin-right: 1.5%; } }

One block in a row:

@media (max-width: 400px) { .child { width: 100%; } }

Let's put all the code together:

.parent { display: flex; flex-wrap: wrap; width: 95%; margin: 50px auto; } .child { box-sizing: border-box; height: 100px; padding: 20px; margin-bottom: 1.5%; border: 1px solid green; } @media (max-width: 400px) { .child { width: 100%; } } @media (min-width: 400px) and (max-width: 700px) { .child { width: calc(100% / 2 - 1.5% * 1 / 2); } .child:not(:nth-child(2n)) { margin-right: 1.5%; } } @media (min-width: 700px) and (max-width: 1000px) { .child { width: calc(100% / 3 - 1.5% * 2 / 3); } .child:not(:nth-child(3n)) { margin-right: 1.5%; } } @media (min-width: 1000px) { .child { width: calc(100% / 4 - 1.5% * 3 / 4); } .child:not(:nth-child(4n)) { margin-right: 1.5%; } }

Since our grid is 3 by 3, there will be no such fourth row and column in this grid. But they will not be in explicit form, that is, in the form we set. But the browser will create them implicit, that is, itself.

Since our grid is 3 by 3, there will be no such fourth row and column in this grid. But they will not be in explicit form, that is, in the form we set. But the browser will create them implicit, that is, itself.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline