-
Notifications
You must be signed in to change notification settings - Fork 1
/
_breakpoints.scss
68 lines (65 loc) · 1.27 KB
/
_breakpoints.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$breakpoints: null;
@mixin register-breakpoints($registering...){
$sorted: 0;
$previous: 0;
@while $sorted < length($registering){
$min: 99999;
@each $amount in $registering{
@if $amount < $min{
@if $amount > $previous{
$min: $amount;
}
}
}
@if nth($breakpoints, 1) == null{
$breakpoints: $min;
}
@else{
$breakpoints: append($breakpoints, $min);
}
$previous: $min;
$sorted: $sorted+1;
}
}
@mixin width-above($breakpoint){
@media only screen and (min-width: $breakpoint){
@content;
}
}
@mixin width-below($breakpoint){
@media only screen and (max-width: $breakpoint){
@content;
}
}
@mixin width-between($start, $end){
@media only screen and (min-width: $start) and (max-width: $end - 1px){
@content;
}
}
@mixin width-matches($size){
$i: 1;
@each $breakpoint in $breakpoints{
@if ($breakpoint == $size){
//we've hit the correct breakpoint
@if $i == 1{
//smallest item in the list
@include width-below(nth($breakpoints, 2) - 1px){
@content;
}
}
@else if $i == length($breakpoints){
//biggest item in the list
@include width-above($size){
@content;
}
}
@else{
//any other item
@include width-between($size, nth($breakpoints, $i+1)){
@content;
}
}
}
$i: $i+1;
}
}