Created
May 4, 2012 01:19
-
-
Save Daniel-Hug/2590942 to your computer and use it in GitHub Desktop.
Pure CSS aspect ratio with no spacer images or js! :)
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
/* | |
* Pure CSS aspect ratio with no spacer images or js! :) | |
*/ | |
body { | |
width: 36%; | |
margin: 8px auto; | |
} | |
div.stretchy-wrapper { | |
width: 100%; | |
padding-bottom: 56.25%; /* 16:9 */ | |
position: relative; | |
background: blue; | |
} | |
div.stretchy-wrapper > div { | |
position: absolute; | |
top: 0; bottom: 0; left: 0; right: 0; | |
color: white; | |
font-size: 24px; | |
text-align: center; | |
} | |
/* Other aspect ratios to try: | |
* 56.25% = 16:9 | |
* 75% = 4:3 | |
* 66.66% = 3:2 | |
* 62.5% = 8:5 | |
*/ |
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="stretchy-wrapper"><div>Resize your browser</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
{"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