Skip to content

Instantly share code, notes, and snippets.

@c0defre4k
Last active March 21, 2018 14:57
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 c0defre4k/9699b11263ca6df239be3962eb1d0e01 to your computer and use it in GitHub Desktop.
Save c0defre4k/9699b11263ca6df239be3962eb1d0e01 to your computer and use it in GitHub Desktop.
Variable ratios for responsive embeds
.embed-responsive-21by9::before {
padding-top: 42.85714%;
}
.embed-responsive-16by9::before {
padding-top: 56.25%;
}
.embed-responsive-4by3::before {
padding-top: 75%;
}
.embed-responsive-1by1::before {
padding-top: 100%;
}
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
$embed-ratios: (
21 9,
16 9,
4 3,
1 1
) !default;
// generate embeds
@each $ratio in $embed-ratios {
.embed-responsive-#{nth($ratio, 1)}by#{nth($ratio, 2)} {
&::before {
padding-top: percentage(nth($ratio, 2) / nth($ratio, 1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment