html - Centering absolutely positioned element in CSS Grid -
on mozilla pen works. when switch chrome breaks.
it's me or wrong browsers?
.container { height: 500px; width: 500px; background-color: beige; display: grid; grid-template-rows: 1fr; grid-template-columns: 1fr; } .container h2 { position: absolute; justify-self: center; align-self: center; grid-row: 1; grid-column: 1; }
<div class="container"> <h2>text</h2> </div>
it appears chrome has deviated spec guidance on issue.
the justify-self
, align-self
properties should work on absolutely-positioned child element of grid container.
an absolutely-positioned child of grid container out-of-flow , not grid item, , not affect placement of other items or sizing of grid.
the static position of absolutely-positioned child of grid container determined if sole grid item in grid area edges coincide padding edges of grid container.
note position affected values of
justify-self
,align-self
on child.
so, firefox seems have right.
for other centering options see post:
Comments
Post a Comment