Skip to content

Instantly share code, notes, and snippets.

@joechan3
Created June 16, 2016 03:28
Show Gist options
  • Save joechan3/3970538e9fe7a2ccee645296dc2c4e46 to your computer and use it in GitHub Desktop.
Save joechan3/3970538e9fe7a2ccee645296dc2c4e46 to your computer and use it in GitHub Desktop.
Container which maintains the ratio
<!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