Created
August 10, 2014 18:29
-
-
Save obenjiro/6b215d7378bc186eacbb to your computer and use it in GitHub Desktop.
Css only background-size: cover emulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* you can see it in action here http://jsbin.com/joxinizo/4/edit */ | |
html, body { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
.bgd { | |
position: relative; | |
width: 100%; | |
height: 33%; | |
overflow: hidden; | |
} | |
.bgd-cover { | |
position: absolute; | |
top: 0; | |
left: -50%; | |
width: 200%; | |
height: 100%; | |
overflow: hidden; | |
} | |
.bgd-cover-img { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
margin: auto; | |
min-width: 50%; | |
min-height: 13%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<meta name="viewport" content="width=device-width"> | |
</head> | |
<body> | |
<div class="bgd"> | |
<div class="bgd-cover"> | |
<img | |
src="http://placehold.it/800x400" | |
alt="" | |
class="bgd-cover-img"> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment