If you needed to horizontally and vertically center an object within a container that has no set height, how would you accomplish that?
Asked
Active
Viewed 41 times
-2
-
1https://www.w3.org/Style/Examples/007/center.en.html – Michael Coker Jul 21 '17 at 18:22
-
1display grid, flex, table-cell, ... ? have you tried anything yet ? – G-Cyrillus Jul 21 '17 at 18:27
-
4Possible duplicate of [How to vertically center content with variable height within a div?](https://stackoverflow.com/questions/59309/how-to-vertically-center-content-with-variable-height-within-a-div) – hidanielle Jul 21 '17 at 18:50
1 Answers
0
.centerDiv {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="centerDiv">hello</div>

Pawan Kumar
- 1,374
- 7
- 14