Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Created August 5, 2022 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poudelmadhav/73f9369aed07bd9b82ddf2f23d81f056 to your computer and use it in GitHub Desktop.
Save poudelmadhav/73f9369aed07bd9b82ddf2f23d81f056 to your computer and use it in GitHub Desktop.
Align content horizontally and vertically center
<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>
/* 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