forked from leafo/scssphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathat_root.scss
More file actions
234 lines (211 loc) · 3.76 KB
/
at_root.scss
File metadata and controls
234 lines (211 loc) · 3.76 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
.parent-inline-selector {
color: white;
@at-root .child { color: black; }
}
.parent-block {
color: white;
@at-root {
.child1 { color: green; }
.child2 { color: blue; }
}
.step-child { color: black; }
}
.first {
color: red;
}
body{
.second {
color: white;
@at-root {
.nested1 {
color: blue;
@at-root {
.nested2 {
color: yellow;
}
}
color: orange;
}
}
color: black;
}
}
.third {
color: green;
}
@media print {
.page {
width: 8in;
@at-root (without: media) {
color: red;
}
}
}
.my-widget {
@media (min-width: 300px) {
.inside-mq {
inside-style: mq;
}
@at-root (without: media){
//this without:media tells the screen what to bust out of
.outside-mq {
outside-style: mq;
}
}
// using (without:all) forces all nested selectors outside of all media
// queries, hence color:blue only in the .outside-everything class in generated css
@at-root (without:all){
.outside-class {
color: blue;
}
}
// using the (with:media) keeps .with-only inside media query hence .with-only selector
// inside @media ()min-width:300px
@at-root (with: media) {
.with-only {
// do this ONLY inside mq
color: pink;
}
}
}
}
// without: rule - default - outside of all css rules, but inside directives
@media screen and (max-width:320px) {
.foo {
margin: 0;
@at-root (without: rule) {
.bar {
padding: 0;
}
}
@at-root (without: media rule) {
.baar {
padding: 0;
}
}
@at-root (without: media) {
.barr {
padding: 0;
}
}
}
}
// with: rule - outside of all directives but preserve any css rules
@media screen and (max-width:640px) {
.foo {
@supports ( display: flex ) {
@at-root (with: rule) {
.bar {
width: 0;
}
}
@at-root (with: supports) {
.baz {
height: 0;
}
}
@at-root (with: media) {
.qux {
margin: 0;
}
}
@at-root (with: media rule) {
.quux {
padding: 0;
}
}
@at-root (with: rule) {
.quix {
padding: 0;
}
}
}
}
}
$table-padding: 10px !default;
@mixin table($padding: $table-padding) {
@at-root {
tbody {
padding: $padding;
}
}
}
.test{
.test2{
padding: 0px;
@include table;
}
}
.badge {
@at-root a#{&} {
text-decoration: none;
}
}
@mixin badge-variant($bg) {
background-color: $bg;
@at-root a#{&} {
&:focus,
&.focus {
outline: 0;
}
}
}
.badge-primary {
@include badge-variant(blue);
}
.badge-secondary {
@include badge-variant(yellow);
}
// combine everything in one: several levels of selecors, mixin, at-root and self
@mixin mixin-hover {
&:hover { @content; }
@at-root #{&}.foo {
color:red;
}
}
.table-hover, .table2#id {
tbody tr {
@include mixin-hover {
color: #ddd;
background-color: #eee;
}
}
}
// self propagation to @include and previous media poisoning in @at-root
@mixin transition($transition...) {
@media (prefers-reduced-motion: reduce) {
transition: none;
}
}
@mixin hover-focus {
&:hover,
&:focus {
@content;
}
}
.badge {
display: inline-block;
@include transition(none);
@at-root a#{&} {
@include hover-focus {
text-decoration: none;
}
}
}
// check that the hover-focus has not been spoiled by previous @at-root call
.btn {
@include hover-focus {
text-decoration: none;
}
}
// variable scoping
$test1: 'foo';
.any {
$test2: 'bar';
@at-root {
.other {
content: "#{$test2}";
content: "#{$test1}";
}
}
}