⊗mkSpGdCHA 111 of 128 menu

Alignment within CSS grid cells along the horizontal axis

To align elements within grid cells, i.e. areas that arise when columns and rows intersect, the justify-items property is used, which is set in the parent element. The alignment can be most clearly seen when viewing the grid in the browser debugger.

At the beginning of the axis

Let's align our elements inside the cells to the start of the horizontal axis:

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> #parent { display: grid; justify-items: start; grid-template-columns: 100px 100px; grid-template-rows: repeat(3, 1fr); grid-gap: 10px; padding: 10px; height: 200px; width: 400px; border: 2px solid #696989; } #parent > div { grid-gap: 10px; padding: 10px; box-sizing: border-box; border: 1px solid #696989; }

:

Now let's look at our grid in the debugger:

At the center of the axis

Let's align our elements in the cells to the center of the horizontal axis:

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> #parent { display: grid; justify-items: center; grid-template-columns: 100px 100px; grid-template-rows: repeat(3, 1fr); 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; }

:

Now let's look at our grid in the debugger:

At the end of the axis

Let's align our elements to the end of the horizontal axis:

<div id="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div> #parent { display: grid; justify-items: end; grid-template-columns: 100px 100px; grid-template-rows: repeat(3, 1fr); 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; }

:

Now let's look at our grid in the debugger:

Practical tasks

Create a grid of five elements arranged in three rows. Align the elements along the horizontal axis.

Now arrange the grid elements in two rows and set the alignment of the elements in the cells to the center of the horizontal axis.

Modify the previous task so that the elements are aligned at the end of the horizontal axis.

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