Skip to content

Instantly share code, notes, and snippets.

@stanwmusic
Created January 19, 2020 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanwmusic/88b625089ca0d9cabd5ce4bcea79c8a5 to your computer and use it in GitHub Desktop.
Save stanwmusic/88b625089ca0d9cabd5ce4bcea79c8a5 to your computer and use it in GitHub Desktop.
Responsive Iframe
<div style="--aspect-ratio: 16/9;">
<iframe
src="https://nativelore.org"
width="1600"
height="900"
frameborder="0"
>
</iframe>
</div>
[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%;
}
}
@stanwmusic
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment