Surprisingly, I can't find anything about this online. Maybe I've missed something. How do you horizontally and vertically center your entire main wrapper with CSS Grid, and obviously, maintain responsiveness?
.wrapper {
display: grid;
grid-template-columns: minmax(100vw, 1fr);
grid-template-rows: minmax(100vh, 1fr);
align-items: center;
justify-content: center;
}
<div class="wrapper">
<div class="centerthis">loremloremlorem</div>
</div>
Using the CSS above, the div
is centered vertically, but not horizontally.
The following CSS centers the div horizontally, but not vertically:
.maingrid {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
align-items: center;
justify-content: center;
}
.centerthis {
align-self: center;
justify-self: center;
}
<div class="maingrid">
<div class="centerthis">loremloremlorem</div>
</div>