Skip to content

Instantly share code, notes, and snippets.

@sms-system
Last active May 26, 2016 14:07
Show Gist options
  • Save sms-system/85d07497dcf957ca850065c0bafaaff2 to your computer and use it in GitHub Desktop.
Save sms-system/85d07497dcf957ca850065c0bafaaff2 to your computer and use it in GitHub Desktop.
Ratio box in css
.a {
width: 900px;
position: relative;
}
.a:before {
content: '';
display: block;
width: 100%;
padding-bottom: 56.25%;
position: relative;
}
.b {
position: absolute;
bottom: 0;
right: 0;
left: 0;
top: 0;
background: #ccc;
}
.content {
position: absolute;
top: 50%;
left: 50%;
width: 200px;
text-align: center;
height: 100px;
line-height: 100px;
margin: -50px 0 0 -100px;
background: #777;
color: #fff;
font-size: 20px;
}
<div class="a"><div class="b">
<div class="content">16:9</div>
</div></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment