-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add viewport ratios mixins and variables
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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,45 @@ | ||
/* VIEWPORT RATIO IN FRACTION | ||
* | ||
* Turns a SASS list into resolution custom media queries. | ||
* | ||
* Parameters: | ||
* $ratios: a SASS list with ratios names and their values in fractions | ||
* $from-prefix (`ratio-from-`): the _from_ prefix when resolutions >= density | ||
* $exact-prefix (`ratio-`): the prefix when resolutions == density | ||
* $to-prefix (`ratio-to-`): the _to_ prefix when resolutions < density | ||
* | ||
* Example usage: | ||
* | ||
* $ratios: ('16-9': 16/9, '4-3': 4/3); | ||
* @include --ratio($ratios); | ||
* | ||
* Available custom media queries: | ||
* | ||
* --ratio-from-16-9, --ratio-from-4-3 | ||
* --ratio-16-9, --ratio-4-3 | ||
* --ratio-to-16-9, --ratio-to-4-3 | ||
* | ||
* Note: `aspect-ratio` is prefered over `orientation` because… | ||
* 1. A square viewport (ratio 1/1) is considered as `portrait` orientation; | ||
* 2. `orientation` is limited to two values (`portrait` and `landscape`). | ||
*/ | ||
|
||
@mixin --ratio($ratios, $from-prefix: 'ratio-from-', $exact-prefix: 'ratio-', $to-prefix: 'ratio-to-') { | ||
@each $name, $ratio in $ratios { | ||
@include --ratio-from($name, $ratio, $from-prefix); | ||
@include --ratio-is($name, $ratio, $exact-prefix); | ||
@include --ratio-to($name, $ratio, $to-prefix); | ||
} | ||
} | ||
|
||
@mixin --ratio-from($name, $ratio, $prefix: null) { | ||
@include --media(#{$prefix}#{$name}, 'aspect-ratio >=' #{$ratio}); | ||
} | ||
|
||
@mixin --ratio-is($name, $ratio, $prefix: null) { | ||
@include --media(#{$prefix}#{$name}, unquote('aspect-ratio:') #{$ratio}); | ||
} | ||
|
||
@mixin --ratio-to($name, $ratio, $prefix: null) { | ||
@include --media(#{$prefix}#{$name}, 'aspect-ratio <=' #{$ratio}); | ||
} |
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,17 @@ | ||
/* VIEWPORT ASPECT RATIO | ||
* | ||
* Available custom media queries: | ||
* | ||
* --from-16-9, --is-16-9, --to-16-9 | ||
* | ||
* --landscape, --square, --portrait | ||
*/ | ||
$ratio: ( | ||
'16-9': '16/9', // 1.7777, TV | ||
); | ||
|
||
@include --ratio($ratio, 'from-', 'is-', 'to-'); | ||
|
||
@include --ratio-is('square', '1/1'); | ||
@include --ratio-from('landscape', '10001/10000'); | ||
@include --ratio-to('portrait', '9999/10000'); |
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