Created
June 16, 2016 03:28
-
-
Save joechan3/3970538e9fe7a2ccee645296dc2c4e46 to your computer and use it in GitHub Desktop.
Container which maintains the ratio
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> | |
<style> | |
/* container which maintains the ratio */ | |
/* padding-bottom is the magic rule to set the aspect ration */ | |
.container { | |
position: relative; | |
height: 0; | |
padding-bottom: 50%; | |
} | |
/* the element that lives in the container */ | |
.element { | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 100%; | |
width: 100%; | |
background-color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="element"> | |
</div> <!-- .element --> | |
</div> <!-- .container --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment