Created
August 5, 2022 06:20
-
-
Save poudelmadhav/73f9369aed07bd9b82ddf2f23d81f056 to your computer and use it in GitHub Desktop.
Align content horizontally and vertically center
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="parent"> | |
<section> | |
<h1>Center elements</h1> | |
<p>Center elements vertically or horizontally using following css</p> | |
<pre> | |
<code> | |
.parent { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
flex-direction: column; | |
} | |
</code> | |
</pre> | |
</section> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* You may need to reset margin of body */ | |
body { | |
margin: 0; | |
} | |
/* Horizontally and vertically center the content of its child */ | |
.parent { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
flex-direction: column; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment