I want to center a div without centering its children like so:
<center>
<div>
<h1>Hello World!</h1>
</div>
</center>
As you can see I only want the div to be centered not the h1 inside the div. I want the text to remain to its place only centering the div, not to mention I saw some resources that adds "display: flex;" and "justify-content: center;" in body but this will center all the divs in the page I want it to be applied in the div I choose.
2
Answers
It would center your element without centring its children
You could use
display: flex;
andjustify-content: center;
in a div spanning the entire viewport width that contains the div you want to center.Example: