Skip to content

Instantly share code, notes, and snippets.

@jordaaash
Last active May 23, 2017 08:10
Show Gist options
  • Save jordaaash/3085da7e1e511c070a8f to your computer and use it in GitHub Desktop.
Save jordaaash/3085da7e1e511c070a8f to your computer and use it in GitHub Desktop.
Cross-browser object-fit: cover mixin
cover(width = inherit, height = inherit, min-width = 100%, min-height = 100%)
// Chrome, Safari
@media screen and (-webkit-min-device-pixel-ratio: 0)
object-fit cover
height height
width width
// Firefox
@-moz-document url-prefix()
&
object-fit cover
height height
width width
// Internet Explorer
rules = " height: " + height + ";\n",
" width: " + width + ";\n",
" min-height: " + min-height + ";\n",
" min-width: " + min-width + ";\n",
" position: absolute;\n",
" top: 50%;\n",
" left: 50%;\n",
" -ms-transform: translate(-50%, -50%);\n",
" transform: translate(-50%, -50%);\n"
{ unquote("@media screen\0 {\n " + selector() + " {\n" + rules + " }\n}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment