This repository has been archived by the owner on Oct 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path_media-queries.scss
189 lines (169 loc) · 4.94 KB
/
_media-queries.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* ============================================================================
@CORE -> MIXINS -> MEDIA QUERIES
========================================================================= */
/**
* Setup media query mixins for the following Media features
* (http://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/#media1):
*
* - Width
* - Height
* - Resolution
*
* The width and height mixins are for applying styles based on the width or
* height of the viewport, this can either be a minimum width or height or a
* maximum width or height, or a minimum width or height range or a maximum
* width or height range. The defaults are "width" and "minimum". They accept
* any integer or any of Scally's breakpoints defined here: Core -> Settings
* -> Breakpoints. E.g.
*
@include respond-to(400) {
.foo {background: red;}
}
*
* Would compile to:
*
@media min-width(25em) {
.foo {background: red;}
}
*
* And for a range:
*
@include respond-range(500, 780) {
.foo {background: red;}
}
*
* Would compile to:
*
@media (min-width: 31.25em) and (max-width: 48.75em) {
.foo {background: red;}
}
*
* To apply a maximum width or height the "max" flag needs to be applied e.g.
*
@include respond-to(desk-large, max) {
.foo {background: red;}
}
*
* And for a range:
*
@include respond-range(500, 700, max) {
.foo {background: red;}
}
*
* And to target the height the `$axis` parameter needs to be set to "height"
* e.g.
*
@include respond-to(780, $axis: height) {
.foo {background: red;}
}
*
* And for a range:
*
@include respond-range(500, 700, $axis: height) {
.foo {background: red;}
}
*
* Applying both maximum and height will look something like this:
*
@include respond-to(palm, max, $axis: height) {
.foo {background: red;}
}
*
* For a range it doesn't make sense to pass in the "max" flag as ranges will
* always use a maximum width or height for the second parameter as ranges
* always need to be minimum-maximum however if the second parameter is
* omitted and the first parameter is a Scally breakpoint then the second
* parameter will use the next breakpoint in the sequence. So if you pass in
* the "lap" breakpoint for the first parameter and nothing else for the
* second parameter it will be "lap-large" as "lap-large" comes after "lap".
* E.g.
*
@include respond-range(lap, $axis: height) {
.foo {background: red;}
}
*
* Would compile to:
*
@media (min-height: 40.0625em) and (max-height: 75em) {
.foo {background: red;}
}
*
* Where `max-height: 75em` is the "lap-large" breakpoint.
*
* N.B. the width and height mixins accept unitless integers or integers with
* `px` e.g.
*
@include respond-to(400) {
.foo {background: red;}
}
@include respond-to(400px) {
.foo {background: red;}
}
*
* The resolution mixin is for applying styles to hi-dpi (retina) devices. It
* uses a default resolution defined here: Core -> Settings -> Retina
* Resolution or it will accept either a unitless device pixel ratio (dpr) e.g.
*
@include respond-retina(2) {
.foo {background-size: 100px auto;}
}
*
* Which will compile to a dpi unit using the calculation: "dpr * 96dpi"
* meaning the above mixin will compile too:
*
@media (min-resolution: 192dpi) {
.foo {background-size: 100px auto;}
}
*
* Or it will accept a dpi unit e.g.
*
@media (min-resolution: 192dpi) {
.foo {background-size: 100px auto;}
}
*/
/**
* Simple minimum and maximum width and height values.
*/
@mixin respond-to($value, $limit: "min", $axis: "width") {
@media (#{$limit}-#{$axis}: to-em(strip-unit($value), 16)) {
@content;
}
}
/**
* Ranges.
*/
@mixin respond-range($min-value, $max-value: 0, $axis: "width") {
// If `min-value` is a named breakpoint and `max-value` is omitted use the
// next named breakpoint after the `min-value` breakpoint.
@if type-of($min-value) == "string" and $max-value == 0 {
$breakpoint-values: map-keys($breakpoints);
$breakpoint-index: index($breakpoint-values, $min-value);
@if type-of($breakpoint-index) == "number" {
$next-breakpoint-index: $breakpoint-index + 1;
@if $min-value == "lap" {
$next-breakpoint-index: $breakpoint-index + 2;
}
@if $next-breakpoint-index <= length($breakpoint-values) {
$max-value: nth($breakpoint-values, $next-breakpoint-index);
}
@else {
@warn "No max-#{$axis} value specified and no available breakpoints to use as a substitute";
}
}
@else {
@warn "Breakpoint name '#{$min-value}' not recognised.";
}
}
@media (min-#{$axis}: to-em(strip-unit($min-value), 16)) and (max-#{$axis}: to-em(strip-unit($max-value), 16)) {
@content;
}
}
/**
* Retina.
*/
@mixin respond-retina($resolution: $retina-resolution) {
$resolution: if(unitless($resolution), $resolution * 96dpi, $resolution);
@media (min-resolution: $resolution) {
@content;
}
}