Skip to content

Commit 976efcd

Browse files
MartijnCuppensXhmikosR
authored andcommitted
Allow to add more embed responsive ratios (#25894)
1 parent 9836a41 commit 976efcd

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

scss/_variables.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ $transition-base: all .2s ease-in-out !default;
259259
$transition-fade: opacity .15s linear !default;
260260
$transition-collapse: height .35s ease !default;
261261

262+
$embed-responsive-aspect-ratios: () !default;
263+
// stylelint-disable-next-line scss/dollar-variable-default
264+
$embed-responsive-aspect-ratios: join(
265+
(
266+
(21 9),
267+
(16 9),
268+
(3 4),
269+
(1 1),
270+
),
271+
$embed-responsive-aspect-ratios
272+
);
262273

263274
// Fonts
264275
//

scss/utilities/_embed.scss

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,13 @@
2727
}
2828
}
2929

30-
.embed-responsive-21by9 {
31-
&::before {
32-
padding-top: percentage(9 / 21);
33-
}
34-
}
35-
36-
.embed-responsive-16by9 {
37-
&::before {
38-
padding-top: percentage(9 / 16);
39-
}
40-
}
41-
42-
.embed-responsive-4by3 {
43-
&::before {
44-
padding-top: percentage(3 / 4);
45-
}
46-
}
30+
@each $embed-responsive-aspect-ratio in $embed-responsive-aspect-ratios {
31+
$embed-responsive-aspect-ratio-x: nth($embed-responsive-aspect-ratio, 1);
32+
$embed-responsive-aspect-ratio-y: nth($embed-responsive-aspect-ratio, 2);
4733

48-
.embed-responsive-1by1 {
49-
&::before {
50-
padding-top: percentage(1 / 1);
34+
.embed-responsive-#{$embed-responsive-aspect-ratio-x}by#{$embed-responsive-aspect-ratio-y} {
35+
&::before {
36+
padding-top: percentage($embed-responsive-aspect-ratio-y / $embed-responsive-aspect-ratio-x);
37+
}
5138
}
5239
}

site/docs/4.1/utilities/embed.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Wrap any embed like an `<iframe>` in a parent element with `.embed-responsive` a
2525

2626
## Aspect ratios
2727

28-
Aspect ratios can be customized with modifier classes.
28+
Aspect ratios can be customized with modifier classes. By default the following ratio classes are provided:
2929

3030
{% highlight html %}
3131
<!-- 21:9 aspect ratio -->
@@ -48,3 +48,14 @@ Aspect ratios can be customized with modifier classes.
4848
<iframe class="embed-responsive-item" src="..."></iframe>
4949
</div>
5050
{% endhighlight %}
51+
52+
Within `_variables.scss`, you can change the aspect ratios you want to use. Here's an example of the `$embed-responsive-aspect-ratios` list:
53+
54+
{% highlight scss %}
55+
$embed-responsive-aspect-ratios: (
56+
(21 9),
57+
(16 9),
58+
(3 4),
59+
(1 1)
60+
) !default;
61+
{% endhighlight %}

0 commit comments

Comments
 (0)