A Pen by Stan Williams on CodePen.
Created
January 19, 2020 09:02
-
-
Save stanwmusic/88b625089ca0d9cabd5ce4bcea79c8a5 to your computer and use it in GitHub Desktop.
Responsive Iframe
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
<div style="--aspect-ratio: 16/9;"> | |
<iframe | |
src="https://nativelore.org" | |
width="1600" | |
height="900" | |
frameborder="0" | |
> | |
</iframe> | |
</div> |
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
[style*="--aspect-ratio"] > :first-child { | |
width: 100%; | |
} | |
[style*="--aspect-ratio"] > img { | |
height: auto; | |
} | |
@supports (--custom:property) { | |
[style*="--aspect-ratio"] { | |
position: relative; | |
} | |
[style*="--aspect-ratio"]::before { | |
content: ""; | |
display: block; | |
padding-bottom: calc(100% / (var(--aspect-ratio))); | |
} | |
[style*="--aspect-ratio"] > :first-child { | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo or fork: https://codepen.io/Stanssongs/pen/ExadBKG