Skip to content

Instantly share code, notes, and snippets.

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 aligator28/c75013e3538290172f18c78a8ce08ff0 to your computer and use it in GitHub Desktop.
Save aligator28/c75013e3538290172f18c78a8ce08ff0 to your computer and use it in GitHub Desktop.
div centered horizontally and vertically
//first example (works good)
background: red
position: absolute
color: #fff
top: 50%
left: 50%
padding: 15px
-ms-transform: translateX(-50%) translateY(-50%)
-webkit-transform: translate(-50%,-50%)
transform: translate(-50%,-50%)
//second flexbox
display: flex
align-items: center
//third with table (someone said the safest method)
.top
display: table
height: 100%
margin: 0 auto
position: relative
z-index: 10
color: red
.tbl-cell
display: table-cell
vertical-align: middle
justify-content: center
height: 100%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment