-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#62 responsive embeds
- Loading branch information
Showing
8 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/stylesheets/components/_components-maintain-ratio.scss
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//// | ||
/// @group components | ||
//// | ||
|
||
/// Maintains the aspect ratio of an embedded item, useful for responsive embedding, e.g. | ||
/// YouTube videos in iframes or video tags. Also useful when you know the ratio of an image | ||
/// and want to avoid the 'pop' for slow loading images. | ||
/// | ||
/// Automatically applies to `iframe`, `embed`, `object` and `video` tags. | ||
/// Alternatively, you can use the `__item` selector to specify the element directly. | ||
/// | ||
/// Modifiers: | ||
/// - `--21-9` | ||
/// - `--16-9` | ||
/// - `--4-3` | ||
/// - `--square` | ||
/// | ||
/// Elements: | ||
/// - `__item` | ||
/// | ||
/// @example html - Sixteen by nine example | ||
/// <div class="maintain-ratio maintain-ratio--16-9"> | ||
/// <iframe src="https://www.youtube.com/embed/FTQbiNvZqaY" allowfullscreen></iframe> | ||
/// </div> | ||
/// | ||
/// @example html - Using element | ||
/// <div class="maintain-ratio maintain-ratio--4-3"> | ||
/// <div style="background: #ddd; text-align: center;" class="maintain-ratio__item"> | ||
/// <div style="display: inline-block; font-size: 300%;"> | ||
/// 4:3 | ||
/// </div> | ||
/// <div style="display: inline-block; height: 100%; vertical-align: middle;"></div> | ||
/// </div> | ||
/// </div> | ||
/// | ||
.maintain-ratio { | ||
display: block; | ||
height: 0; | ||
overflow: hidden; | ||
padding: 0; | ||
position: relative; | ||
|
||
&__item, | ||
iframe, | ||
embed, | ||
object, | ||
video { | ||
border: 0; | ||
bottom: 0; | ||
height: 100%; | ||
left: 0; | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
} | ||
|
||
// Modifier class for 21:9 aspect ratio | ||
&--21-9 { | ||
padding-bottom: percentage(9 / 21); | ||
} | ||
|
||
// Modifier class for 16:9 aspect ratio | ||
&--16-9 { | ||
padding-bottom: percentage(9 / 16); | ||
} | ||
|
||
// Modifier class for 4:3 aspect ratio | ||
&--4-3 { | ||
padding-bottom: percentage(3 / 4); | ||
} | ||
|
||
// Modifier class for square aspect ratio | ||
&--square { | ||
padding-bottom: 100%; | ||
} | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% extends "./_components-layout.njk" %} | ||
{% set title = "Maintain ratio" %} | ||
|
||
{% block main %} | ||
|
||
<h1>Maintain ratio</h1> | ||
|
||
<ul> | ||
<li>Used for enforcing an aspect ratio for iframes, videos etc</li> | ||
<li>Use modifiers for different ratios</li> | ||
</ul> | ||
|
||
<p> | ||
<a class="btn" href="/sass/docs/components#css-.maintain-ratio">SASS docs for maintain ratio</a> | ||
</p> | ||
|
||
<h2>Basic usage - 16x9</h2> | ||
|
||
{% example "html" -%} | ||
<div class="maintain-ratio maintain-ratio--16-9"> | ||
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" allowfullscreen></iframe> | ||
</div> | ||
{%- endexample %} | ||
|
||
<h3>Custom - with BEM element</h3> | ||
|
||
{% example "html" -%} | ||
<div class="maintain-ratio maintain-ratio--4-3"> | ||
<img class="maintain-ratio__item" src="http://placehold.it/400x300" alt="An example of an image with a ratio of 4:3" /> | ||
</div> | ||
{%- endexample %} | ||
|
||
{% endblock %} |
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