Skip to content

Instantly share code, notes, and snippets.

@exarcheia-web
Last active November 22, 2016 09:00
Show Gist options
  • Save exarcheia-web/74a6be1839767d3ca3237fc4fe8285a2 to your computer and use it in GitHub Desktop.
Save exarcheia-web/74a6be1839767d3ca3237fc4fe8285a2 to your computer and use it in GitHub Desktop.
Resizing while maintaining a set aspect ratio
/* Resizing while maintaining a set aspect ratio */
.container {
width: 500px; /* you only need to change this to resize the element */
}
.container .ratio-4-3 {
width: 100%;
padding-top: 56.25%; /* set your aspect ratio by changing this... currently set to 16:9 aspect ratio */
position: relative;
}
.content {
box-sizing: border-box;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-image: url("//c2.staticflickr.com/8/7645/27208258473_0a49022518_k.jpg");
background-size: cover;
background-repeat: no-repeat;
background-color: red;
border: 4px solid black
}
<div class="container">
<div class="ratio-4-3">
<div class="content">
</div>
</div>
</div>
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment