Last active
November 22, 2016 09:00
-
-
Save exarcheia-web/74a6be1839767d3ca3237fc4fe8285a2 to your computer and use it in GitHub Desktop.
Resizing while maintaining a set aspect ratio
This file contains hidden or 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
| /* 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 | |
| } |
This file contains hidden or 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
| <div class="container"> | |
| <div class="ratio-4-3"> | |
| <div class="content"> | |
| </div> | |
| </div> | |
| </div> |
This file contains hidden or 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
| // alert('Hello world!'); |
This file contains hidden or 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
| {"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