Responsive Div maintain aspect ratio
by Josh Weir
HTML
<div class = "wrapper">
<div class = "main">
I'm your div with an aspect-ratio of 16:9! <a href = "https://en.wikipedia.org/wiki/Glee_%28TV_series%29">Glee</a> is great!
</div>
</div>
CSS
html, body {
height: 100%;
width: 100%;
}
.wrapper {
width: 50%;
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 56.25%; /*16:9 ratio*/
display: block;
content: '';
}
.main {
position: absolute;
top: 0; bottom: 0; right: 0; left: 0; /*fill parent*/
background-color: rgb(0, 162, 232);
/*I wanted it to look good :)*/
font-family: 'Arial', Helvetica, Sans-Serif;
color: white;
}
/*more irrelevant prettiness*/
a {
text-decoration: none;
font-weight: bold;
color: white;
}
a:hover {
text-decoration: underline;
}