Created
April 22, 2016 17:31
-
-
Save jmc2082/8842da13304a750b2e4cbd3ff95eb9d5 to your computer and use it in GitHub Desktop.
Less / CSS aspect ratio on an html element
This file contains 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
// aspect ratio | |
.try-aspect(@width, @height) { | |
position: relative; | |
&:before { | |
display: block; | |
content: ""; | |
width: 100%; | |
padding-top: (@height / @width) * 100%; | |
} | |
> .content { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
} | |
} | |
.sixteen-nine { | |
.try-aspect(16, 9); | |
background-color: @yellow; | |
} | |
// html | |
<div class="sixteen-nine"> | |
<div class="content"> | |
insert content here | |
this will maintain a 16:9 aspect ratio | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment