Show Menu
Cheatography

Five ways to center DIV element in CSS Cheat Sheet by

Five ways to center DIV element in CSS

Five ways to center <DI­V> element in CSS

USING
CODE
Using flexbox
.parent{
    display:flex;
    justify-content:center;
    align-items:center;
}
Using grid
.parent{
    display: grid;
    place-content:center;
}
Using position
.parent{
    position:relative;
}
.child{
    position:absolute;
    top:50%;
    left:50%;
    transform: transl­ate­(-50%, -50%)
}
Using grid & margin
.parent{
    display:grid;
}
.child{
    margin:auto;
}
Using flex & margin
.parent{
    display:flex;
}
.child{
    margin:auto;
}
                   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Bootstrap Glyphicons Cheat Sheet by James Croft

          More Cheat Sheets by rahilkasimi

          CSS Selectors Cheatsheet Cheat Sheet
          SQL Cheat Sheet