Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 24, 2021 03:11 pm GMT

3 Ways to CENTER a div in CSS

3 ways to center a div in HTML/CSS!!

With Position

/* Using positions */.parent {    position: relative;}.child {    left: 50%;    position: absolute;    top: 50%;    transform: translate(-50%, -50%);}
<div     class="parent"     style="background: blue; width: 500px; height: 250px;"     >    <div         class="child"         style="color: white;"         >      I'm center      </div></div>

With Flexbox

/* Using flexbox */.container-flexbox {    align-items: center;    display: flex;    flex-direction: column;    justify-content: center;}
<div     class="container-flexbox"     style="background: green; width: 500px; height: 250px;"     >    <div         style="color: white;"         >      I'm center      </div></div>

With Grid

/* Using Grid */.container-grid {    display: grid;    place-content: center;}
<div     class="container-flexbox"     style="background: orange; width: 500px; height: 250px;"     >    <div         style="color: white;"         >      I'm center      </div></div>

I hope you like this reading!

You can get my new book Underrated skills in javascript, make the difference for FREE if you follow me on Twitter and send message to me and SAVE 19$

Or get it HERE

For french developper you can check my YoutubeChannel

MY NEWSLETTER

You can SUPPORT MY WORKS

You can follow me on

Twitter : https://twitter.com/code__oz

Github: https://github.com/Code-Oz

And you can mark this article!


Original Link: https://dev.to/codeoz/3-ways-to-center-a-div-in-css-gl1

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To