⊗mkSpGdEASh 118 of 128 menu

Shortcut for aligning a single element in CSS grid

It is possible to align a single element along both the horizontal and vertical axes at the same time. The place-self property is used for this. It takes two values ​​separated by a space. The first value specifies vertical alignment, and the second - horizontal. Let's look at some examples.

In the center of the vertical and the beginning of the horizontal

<div id="parent"> <div id="elem1">1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; 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; } #elem1 { place-self: center start; }

:

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

<div id="parent"> <div id="elem1">1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; 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; } #elem1 { place-self: start end; }

:

At the end of the vertical and in the center of the horizontal

<div id="parent"> <div id="elem1">1</div> <div>2</div> <div>3</div> <div>4</div> </div> #parent { display: grid; 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; } #elem1 { place-self: end center; }

:

Practical tasks

Create a grid of five elements and arrange them in three rows. Align the first element to the start of the horizontal axis and the center of the vertical axis.

Modify the previous problem so that the third element is aligned to the end of the horizontal axis and the center of the vertical axis.

Now arrange the grid elements in two rows and set the alignment of the fifth element to the center of the horizontal axis and the end of the vertical axis.

Make the second element align with the start of the horizontal axis and the end of the vertical axis, and the fourth element align with the center of the horizontal axis and the start of the vertical 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