Created
June 9, 2022 02:01
-
-
Save itsdonnix/f4f9fc091e0eec895224dd10a758ce54 to your computer and use it in GitHub Desktop.
CSS Aspect Ratio with Fallback
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
<!-- | |
CSS Aspect Ratio with Fallback by Una Kravets | |
Source: https://codepen.io/una/pen/BazyaOM | |
--> | |
<div>I am always 16x9</div> | |
<style> | |
div { | |
background: lightblue; | |
width: 100%; | |
// New aspect-ratio property | |
aspect-ratio: 16 / 9; | |
} | |
// Fallback (current, using padding hack) | |
@supports not (aspect-ratio: 16 / 9) { | |
div::before { | |
float: left; | |
padding-top: 56.25%; | |
content: ''; | |
} | |
div::after { | |
display: block; | |
content: ''; | |
clear: both; | |
} | |
} | |
</style> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment