Skip to content

Instantly share code, notes, and snippets.

@Borovensky
Last active April 9, 2016 20:29
Show Gist options
  • Save Borovensky/dcb1da5561ced3053ed5db07d812b71b to your computer and use it in GitHub Desktop.
Save Borovensky/dcb1da5561ced3053ed5db07d812b71b to your computer and use it in GitHub Desktop.
/* SASS version */
/* Negative indent */
.parent
width: 100%
height: 100%
position: absolute
top: 0
left: 0
overflow: auto
.block
width: 250px
height: 250px
position: absolute
top: 50%
left: 50%
margin: -125px 0 0 -125px
img
max-width: 100%
height: auto
display: block
margin: 0 auto
border: none
/* Automatic indentation */
.parent
width: 100%
height: 100%
position: absolute
top: 0
left: 0
overflow: auto
.block
width: 250px
height: 250px
position: absolute
top: 0
right: 0
bottom: 0
left: 0
margin: auto
img
max-width: 100%
height: auto
display: block
margin: 0 auto
border: none
/* Table */
.parent
width: 100%
height: 100%
display: table
position: absolute
top: 0
left: 0
.inner
display: table-cell
text-align: center
vertical-align: middle
.block
display: inline-block
img
display: block
border: none
/* Pseudo-element */
.parent
width: 100%
height: 100%
position: absolute
top: 0
left: 0
overflow: auto
white-space: nowrap
text-align: center
font-size: 0
&:before
height: 100%
display: inline-block
vertical-align: middle
content: ''
.block
display: inline-block
white-space: normal
vertical-align: middle
text-align: left
img
display: block
border: none
/* Flexbox */
.parent
width: 100%
height: 100%
position: fixed
top: 0
left: 0
display: flex
align-items: center
justify-content: center
overflow: auto
.block
background: #60a839
img
display: block
border: none
/* Button */
.parent
width: 100%
height: 100%
position: absolute
top: 0
left: 0
overflow: auto
background: none
border: none
outline: none
.block
display: inline-block
img
display: block
border: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment