⊗mkSpGdTBA 110 of 128 menu

Aligning Content Across Both Axes in CSS Grid

Often in a grid you may want to align content along both the horizontal and vertical axes of the grid. For this purpose, we can use together the two properties you covered in the previous lesson: justify-content and align-content.

At the beginning of the vertical and the end of the horizontal

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; justify-content: flex-end; align-content: flex-start; grid-template-columns: 100px 100px; grid-gap: 10px; padding: 10px; border: 2px solid #696989; height: 200px; width: 400px; } #parent > div { grid-gap: 10px; padding: 10px; box-sizing: border-box; border: 1px solid #696989; }

:

At the end of the vertical and the beginning of the horizontal

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; justify-content: flex-start; align-content: flex-end; grid-template-columns: 100px 100px; grid-gap: 10px; padding: 10px; border: 2px solid #696989; height: 200px; width: 400px; } #parent > div { grid-gap: 10px; padding: 10px; box-sizing: border-box; border: 1px solid #696989; }

:

Ppo center of vertical axis and horizontal

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; justify-content: flex-end; align-content: center; grid-template-columns: 100px 100px; grid-gap: 10px; padding: 10px; border: 2px solid #696989; height: 200px; width: 400px; } #parent > div { grid-gap: 10px; padding: 10px; box-sizing: border-box; border: 1px solid #696989; }

:

Practical tasks

Create a grid of six elements and arrange them in two columns. Align the elements to the start of the horizontal axis and the center of the vertical axis of the grid.

Now arrange the grid items across three columns and set the alignment of the items to the center of the horizontal axis and the end of the vertical axis of the grid.

Modify the previous task so that elements are aligned to the end of the horizontal and center of the vertical grid axes.

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