-
Notifications
You must be signed in to change notification settings - Fork 66
/
mixins.scss
1085 lines (1007 loc) · 26.2 KB
/
mixins.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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! sass-mixins - v0.13.0 - 2020-03-30 */
///
/// Add animation to element.
///
/// @author drublic
///
/// @link http://caniuse.com/#feat=css-animation caniuse
/// @link http://www.w3.org/TR/css3-animations spec
///
/// @param {List} $values
///
/// @output
/// ```css
/// -webkit-animation: <values>;
/// animation: <values>;
/// ```
///
/// @example
/// .selector {
/// @include x-animation(jump 1s ease-out);
/// }
///
@mixin x-animation ($values) {
-webkit-animation: $values;
animation: $values;
}
///
/// Generates keyframe animations.
///
/// @param {String} $name
///
/// @example
/// @include x-keyframes(jump) {
/// from { top: 0; }
/// to { top: -10px; }
/// }
///
@mixin x-keyframes ($name) {
@-webkit-keyframes #{$name} {
@content;
}
@keyframes #{$name} {
@content;
}
}
///
/// Generates appearance for a given element.
///
/// @author romamatusevich
///
/// @link http://caniuse.com/#feat=css-appearance caniuse
/// @link http://www.w3.org/TR/2004/CR-css3-ui-20040511/#appearance spec
/// @link https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-appearance MDN
/// @link http://css-tricks.com/almanac/properties/a/appearance css-tricks
///
/// @param {String} $value
///
/// @output
/// ```css
/// -webkit-appearance: <value>;
/// -moz-appearance: <value>;
/// appearance: <value>;
/// ```
///
/// @example
/// .selector {
/// @include x-appearance(button);
/// }
///
@mixin x-appearance ($value) {
-webkit-appearance: $value;
-moz-appearance: $value;
appearance: $value;
}
///
/// Generates `background-size` output for a given element.
///
/// @author drublic
///
/// @link http://caniuse.com/background-img-opts caniuse
/// @link http://www.w3.org/TR/css3-background spec
///
/// @param {List} $values
///
/// @output
/// ```css
/// -webkit-background-size: $values;
/// background-size: $values;
/// ```
///
/// @example
/// .selector {
/// @include x-background-size(100% auto);
/// }
///
@mixin x-background-size ($values...) {
-webkit-background-size: $values; // For Android 2.x
background-size: $values;
}
///
/// Generates cross-browser-compatible `border-radius` for a given element.
///
/// @author drublic
///
/// @link http://caniuse.com/border-radius caniuse
/// @link http://www.w3.org/TR/css3-background/#corners spec
///
/// @param {List} $values
///
/// @output
/// ```css
/// -webkit-border-radius: <values>;
/// border-radius: <values>;
/// ```
///
/// @example
/// .selector {
/// @include x-border-radius(20px 10px);
/// }
///
@mixin x-border-radius ($values) {
-webkit-border-radius: $values; // iOS Safari 3.2, Android 2.1
border-radius: $values;
}
///
/// Generates cross-browser-compatible `box-shadow` for a given element.
///
/// @author drublic
///
/// @link http://caniuse.com/css-boxshadow caniuse
/// @link http://www.w3.org/TR/css3-background/#the-box-shadow spec
///
/// @param {List} $values
///
/// @output
/// ```css
/// -webkit-box-shadow: <values>;
/// box-shadow: <values>;
/// ```
///
/// @example
/// .selector {
/// @include x-box-shadow(5px 5px 10px 5px #aaa);
/// }
///
@mixin x-box-shadow ($values...) {
-webkit-box-shadow: $values; // iOS Safari 3.2 - 4.3, Android 2.1+
box-shadow: $values;
}
///
/// Generates cross-browser-compatible `box-sizing` output for a given element.
///
/// @author drublic
///
/// @link http://caniuse.com/#feat=css3-boxsizing caniuse
/// @link http://www.w3.org/TR/css3-ui/#box-sizing spec
///
/// @param {String} $type [border-box]
///
/// @output
/// ```css
/// -webkit-box-sizing: <type>;
/// -moz-box-sizing: <type>;
/// box-sizing: <type>;
/// ```
///
/// @example
/// .selector {
/// @include x-box-sizing;
/// }
///
@mixin x-box-sizing ($type: border-box) {
-webkit-box-sizing: $type; // Safari <= 5.0, Chrome <= 9.0, iOS Safari 3.2 - 4.3 and Android 2.1 - 3.0
-moz-box-sizing: $type; // FF 2.0 - 28.0
box-sizing: $type; // IE 8, Opera 9.5+
}
///
/// Add Breakpoint greater than the specified device-width.
///
/// @author drublic
///
/// @link http://caniuse.com/#feat=css-mediaqueries caniuse
/// @link http://www.w3.org/TR/css3-mediaqueries spec
///
/// @param {Number} $device-width
///
/// @output
/// ```css
/// @media screen and (min-width: <device-width>) {
/// <content>
/// }
/// ```
///
/// @example
/// Note: Please use the CSS unit `em` for device-width in order to stay
/// responsive.
/// ```css
/// .selector {
/// @include x-at-least(40em) { width: 60%; }
/// }
/// ```
///
@mixin x-at-least ($device-width) {
@media screen and (min-width: $device-width) {
@content;
}
}
///
/// Add Breakpoint until the specified device-width.
///
/// @param {Number} $device-width
///
/// @output
/// ```css
/// @media screen and (max-width: <device-width - 0.01>) {
/// <content>
/// }
/// ```
///
/// @example
/// .selector {
/// @include x-until(40em) { width: 100%; }
/// }
///
@mixin x-until ($device-width) {
@media screen and (max-width: $device-width - 0.01) {
@content;
}
}
///
/// Add Breakpoint between specified device-widths.
///
/// @author romamatusevich
///
/// @param {String} $point
/// @param {Number} $bp-mobile-width [640px]
/// @param {Number} $bp-tablet-width [1024px]
///
/// @output
/// ```css
/// @media (max-width: <bp-mobile-width>) {
/// <content>
/// }
/// ```
///
/// @example
/// .selector {
/// @include x-breakpoints(mobile, 320px) { width: 100%; }
/// }
///
@mixin x-breakpoints($point, $bp-mobile-width: 640px, $bp-tablet-width: 1024px) {
$bp-mobile: '(max-width: #{$bp-mobile-width})';
$bp-tablet: '(min-width: #{$bp-mobile-width}) and (max-width: #{$bp-tablet-width})';
$bp-desktop: '(min-width: #{$bp-tablet-width})';
@if $point == mobile {
@media #{$bp-mobile} {
@content;
}
}
@else if $point == tablet {
@media #{$bp-tablet} {
@content;
}
}
@else if $point == desktop {
@media #{$bp-desktop} {
@content;
}
}
@else {
@warn "You are requesting an invalid breakpoint: `#{$point}`.";
}
}
///
/// Generates `calc` function which allows mathematical expressions for a given property.
///
/// @author romamatusevich
///
/// @link http://caniuse.com/calc caniuse
/// @link http://www.w3.org/TR/css3-values/#calc spec
///
/// @param {String} $property
/// @param {String} $expression
///
/// @output
/// ```css
/// <property>: -webkit-calc(<expression>);
/// <property>: calc(<expression>);
/// ```
///
/// @example
/// .selector {
/// @include x-calc(width, "600px - 2em");
/// }
///
@mixin x-calc ($property, $expression) {
#{$property}: -webkit-calc(#{$expression});
#{$property}: calc(#{$expression});
}
///
/// Generates flexbox properties for a given element.
///
/// @author romamatusevich
///
/// @link http://caniuse.com/#feat=flexbox caniuse
/// @link http://www.w3.org/TR/css3-flexbox spec
/// @link https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes MDN
/// @link http://css-tricks.com/snippets/css/a-guide-to-flexbox css-tricks
///
/// @output
/// ```css
/// display: -webkit-box;
/// display: -moz-box;
/// display: -ms-flexbox;
/// display: -webkit-flex;
/// display: flex;
/// ```
///
/// @example
/// .selector {
/// @include x-display-flex;
/// }
///
@mixin x-display-flex {
display: -webkit-box; // Chrome 20-, iOS 6-, Safari 3.1 -6
display: -moz-box; // FF 19-
display: -webkit-flex; // Chrome 21 - 28
display: -ms-flexbox; // IE 10
display: flex; // FF 20+, Chrome 29+, Opera 12.1, 17+
}
///
/// Add flex values to element.
///
/// @param {Arglist} $values
///
/// @output
/// ```css
/// -webkit-box-flex: <values>;
/// -moz-box-flex: <values>;
/// -webkit-flex: <values>;
/// -ms-flex: <values>;
/// flex: <values>;
/// ```
///
/// @example
/// .selector {
/// @include x-flex(1 1 auto);
/// }
///
@mixin x-flex ($values...) {
-webkit-box-flex: $values; // Chrome 20-, iOS 6-, Safari 3.1 - 6
-moz-box-flex: $values; // FF 19-
-webkit-flex: $values; // Chrome 21 - 28
-ms-flex: $values; // IE 10
flex: $values; // FF 20+, Chrome 29+, Opera 12.1, 17+
}
///
/// Add flex order to element.
///
/// @param {Number} $value
///
/// @output
/// ```css
/// -webkit-box-ordinal-group: <value>;
/// -moz-box-ordinal-group: <value>;
/// -ms-flex-order: <value>;
/// -webkit-order: <value>;
/// order: <value>;
/// ```
///
/// @example
/// .selector {
/// @include x-order(1);
/// }
///
@mixin x-order ($value) {
-webkit-box-ordinal-group: $value; // Chrome 20-, iOS 6-, Safari 3.1 - 6
-moz-box-ordinal-group: $value; // FF 19-
-ms-flex-order: $value; // IE 10
-webkit-order: $value; // Chrome 21 - 28
order: $value; // FF 20+, Chrome 29+, Opera 12.1, 17+
}
///
/// Add flex wrap to element.
///
/// @param {String} $value
///
/// @output
/// ```css
/// -webkit-flex-wrap: <value>;
/// -ms-flex-wrap: <value>;
/// flex-wrap: <value>;
/// ```
///
/// @example
/// .selector {
/// @include x-flex-wrap(wrap);
/// }
///
@mixin x-flex-wrap ($value) {
// IE 10
@if $value == nowrap {
-ms-flex-wrap: none;
} @else {
-ms-flex-wrap: $value;
}
-webkit-flex-wrap: $value; // Chrome 20-, iOS 6-, Safari 3.1 - 6
flex-wrap: $value; // FF 28+, Chrome 21+, Opera 12.1, 17+, IE 11
}
///
/// Add flex align-content to element.
///
/// @param {String} $value
///
/// @output
/// ```css
/// -webkit-align-content: <value>;
/// -moz-align-content: <value>;
/// -ms-flex-line-pack: <value>;
/// align-content: <value>;
/// ```
/// @example
/// .selector {
/// @include x-align-content(center);
/// }
///
@mixin x-align-content ($value) {
// IE 10
@if $value == flex-start {
-ms-flex-line-pack: start;
} @else if $value == flex-end {
-ms-flex-line-pack: end;
} @else if $value == space-between {
-ms-flex-line-pack: justify;
} @else if $value == space-around {
-ms-flex-line-pack: distribute;
} @else {
-ms-flex-line-pack: $value;
}
-webkit-align-content: $value; // Chrome 20-, iOS 6-, Safari 3.1 - 6
-moz-align-content: $value; // FF 19-
align-content: $value; // FF 20+, Chrome 21+, Opera 12.1, 17+, IE 11
}
///
/// Add flex direction to element.
///
/// @param {String} $value
///
/// @output
/// ```css
/// -webkit-box-direction: <value>;
/// -moz-box-direction: <value>;
/// -webkit-box-orient: <value>;
/// -moz-box-orient: <value>;
/// -webkit-flex-direction: <value>;
/// -moz-flex-direction: <value>;
/// -ms-flex-direction: <value>;
/// flex-direction: <value>;
/// ```
///
/// @example
/// .selector {
/// @include x-flex-direction(row-reverse);
/// }
///
@mixin x-flex-direction ($value) {
@if $value == row {
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
} @else if $value == row-reverse {
-webkit-box-direction: reverse;
-moz-box-direction: reverse;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
} @else if $value == column {
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
} @else if $value == column-reverse {
-webkit-box-direction: reverse;
-moz-box-direction: reverse;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
}
-webkit-flex-direction: $value;
-moz-flex-direction: $value;
-ms-flex-direction: $value;
flex-direction: $value;
}
//todo: add flex-grow, flex-shrink, flex-basis, flex-flow, align-items, align-self, justify-content mixins
///
/// Helper for old syntax (for Angles) in linear-gradients.
///
/// @param {Number|String} $deg
///
/// @return {Number|String} - Return the corrected angle or position for a css gradient
///
@function angle ($deg) {
@if type-of($deg) == 'number' {
@return mod(abs($deg - 450), 360deg);
} @else {
$position: to + " ";
@each $pos in $deg {
$position: $position + opposite-position($pos) + " ";
}
@return $position;
}
}
///
/// Get the old direction keyword syntax for gradients, for backward compability.
///
/// @param {String} $direction
///
/// @return {String}
///
@function helper-gradient-angle ($direction) {
$old-direction: $direction;
$veryold-direction: $direction;
// New Syntax has to be evaluated to old one
@if $direction == 'to bottom' {
$old-direction: 'top';
} @else if $direction == 'to right' {
$old-direction: 'left';
} @else if $direction == 'to top' {
$old-direction: 'bottom';
} @else if $direction == 'to left' {
$old-direction: 'right';
} @else {
$old-direction: angle($direction);
}
// And also for very old syntax
@if $direction == 'to bottom' {
$veryold-direction: 'left top, left bottom';
} @else if $direction == 'to right' {
$veryold-direction: 'top left, bottom right';
} @else if $direction == 'to top' {
$veryold-direction: 'left bottom, left top';
} @else if $direction == 'to left' {
$veryold-direction: 'top right, bottom left';
} @else {
$veryold-direction: angle($direction);
}
@return $old-direction, $veryold-direction;
}
///
/// Generates a linear gradient for a given element with a fallback color.
///
/// Note: By default this linear-gradient-mixin encourages people to use the
/// latest CSS-syntax for gradients.
///
/// @author drublic
///
/// @link http://caniuse.com/#feat=css-gradients caniuse
/// @link https://drafts.csswg.org/css-images-3/#linear-gradients spec
///
/// @require helper-gradient-angle
///
/// @param {String | Angle} $direction [to bottom] - Either an angle value or any of `to bottom`, `to right`, `to top` or `to left`
/// @param {Color} $fallback [#ccc]
/// @param {Color} $from [#ccc]
/// @param {Color} $to [#aaa]
///
/// @output
/// ```css
/// background-color: <fallback>;
/// background-image: -webkit-gradient(linear, <direction - old converted>, from(<from>), to(<to>));
/// background-image: -webkit-linear-gradient(<direction - converted>, <from>, <to>);
/// background-image: linear-gradient(<direction>, <from>, <to>);
/// ```
///
/// @example
/// .selector {
/// @include x-linear-gradient('to bottom', #ccc, #ddd, #bbb);
/// }
///
@mixin x-linear-gradient ($direction: 'to bottom', $fallback: #ccc, $from: #ccc, $to: #aaa) {
$directions: helper-gradient-angle($direction);
// Provide a fallback-color
background-color: $fallback;
// Cross-browser linear-gradients
background-image: -webkit-gradient(linear, unquote(nth($directions, 2)), from($from), to($to)); // Android 2.1-3.0
background-image: -webkit-linear-gradient(unquote(nth($directions, 1)), $from, $to);
background-image: linear-gradient(unquote($direction), $from, $to);
}
///
/// A function for prefixing gradients.
///
/// @todo define old webkit mode
///
/// @param {String} $mode - Either `webkit-old`, `webkit` or `''`
/// @param {Arglist} $gradient
///
/// @returns {String} `-<mode>-linear-gradient(<gradient>)`
///
@function prefixed-gradient ($mode, $gradient) {
$prefix: '-' + $mode + '-';
// Get angles
$angles: helper-gradient-angle('' + nth($gradient, 2));
$angle: nth($angles, 1);
// If unprefixed
@if ($mode == '') {
$prefix: '';
$angle: nth($gradient, 2);
}
// @TODO define old webkit mode
@if ($mode == 'webkit-old') {
$prefix: '-webkit-';
$angle: nth($angles, 2);
}
$prefixed: $prefix + 'linear-gradient(' + $angle;
@for $i from 1 through length($gradient) {
@if ($i > 2) {
$prefixed: append(unquote($prefixed), nth($gradient, $i), comma);
}
}
$prefixed: $prefixed + ')';
@return unquote($prefixed);
}
///
/// This mixin generates multiple backgrounds.
///
/// @author drublic
///
/// @link http://caniuse.com/css-gradients caniuse
/// @link http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients spec
///
///
/// @param {Arglist} $backgrounds
///
/// @example
/// .selector {
/// @include x-multiple-backgrounds(
/// rgba(0, 0, 0, 0.3),
/// url('../img/html5_logo.png') top right no-repeat,
/// (linear-gradient, to bottom, #aaa, #ddd)
/// );
/// }
///
@mixin x-multiple-backgrounds ($backgrounds...) {
$combined-background-webkit-old: ();
$combined-background-webkit: ();
$combined-background: ();
$end: '';
// Iterate through all backgrounds passed
@each $background in $backgrounds {
// Prefix gradients
@if (type-of($background) == list) {
@if (nth($background, 1) == 'linear-gradient') {
$combined-background-webkit-old: append($combined-background-webkit-old, prefixed-gradient('webkit-old', $background), comma);
$combined-background-webkit: append($combined-background-webkit, prefixed-gradient('webkit', $background), comma);
$combined-background: append($combined-background, prefixed-gradient('', $background), comma);
// Nothing to do for non-gradients
} @else {
$combined-background-webkit-old: append($combined-background-webkit-old, $background, comma);
$combined-background-webkit: append($combined-background-webkit, $background, comma);
$combined-background: append($combined-background, $background, comma);
}
// Put colors at end of combined background
} @else if (type-of($background) == color) {
$end: $background;
$background: null;
} @else if (type-of($background) == string) {
$combined-background-webkit-old: append($combined-background-webkit-old, $background, space);
$combined-background-webkit: append($combined-background-webkit, $background, comma);
$combined-background: append($combined-background, $background, comma);
}
}
// Append color if there is one
@if $end != '' {
$combined-background-webkit-old: append($combined-background-webkit-old, $end, space);
$combined-background-webkit: append($combined-background-webkit, $end, comma);
$combined-background: append($combined-background, $end, comma);
}
// Only print all prefixed versions if necessary
@if ($combined-background != $combined-background-webkit) {
background: unquote($combined-background-webkit-old);
background: unquote($combined-background-webkit);
background: unquote($combined-background);
} @else {
background: unquote($combined-background);
}
}
///
/// This mixin creates (endless) multiple color stops in gradients just with one
/// call for the mixin.
///
/// Note: This mixin does not define a fallback-color for your background as it
/// is likely you want to add an image or something. Please specify one by
/// yourself.
///
/// @author drublic
///
/// @link http://caniuse.com/css-gradients caniuse
/// @link http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients spec
///
/// @param {Arglist} $args
///
/// @output
/// ```css
/// background-image: -webkit-linear-gradient(top, <stops[1]>, <stops[2]>, ..., <stops[n]>);
/// background-image: linear-gradient(to bottom, <stops[1]>, <stops[2]>, ..., <stops[n]>);
/// ```
///
/// @example
/// .selector {
/// @include x-multiple-colored-gradient(
/// 'top',
/// #f22 0%,
/// #f2f 15%,
/// #22f 30%,
/// #2ff 45%,
/// #2f2 60%,
/// #2f2 75%,
/// #ff2 90%,
/// #f22 100%
/// );
/// }
///
@mixin x-multiple-colored-gradient ($args...) {
$gradient: ();
$pos: nth($args, 1);
$pos_newsyntax: ();
@if not is-valid-keyword-direction($pos) {
$pos: 'top';
}
// New Syntax
@if $pos == 'top' {
$pos_newsyntax: 'to bottom';
} @else if $pos == 'right' {
$pos_newsyntax: 'to left';
} @else if $pos == 'bottom' {
$pos_newsyntax: 'to top';
} @else if $pos == 'left' {
$pos_newsyntax: 'to right';
}
@each $g in $args {
@if not is-valid-keyword-direction($g) {
$gradient: append($gradient, $g, comma);
}
}
background-image: -webkit-linear-gradient(unquote($pos), $gradient);
background-image: linear-gradient(unquote($pos_newsyntax), $gradient);
}
///
/// Returns whether a value is a valid keyword direction.
///
/// @param {String} $value
///
/// @returns {Bool}
///
@function is-valid-keyword-direction($value) {
@return not not index(
'top' 'right' 'bottom' 'left'
'to top' 'to right' 'to bottom' 'to left'
'to top right' 'to right top'
'to bottom right' 'to right bottom'
'to top left' 'to left top'
'to bottom left' 'to left bottom', $value);
}
///
/// Generates `opacity` output for a given element and adds a filter for old IE.
///
/// @author bartveneman
///
/// @link http://caniuse.com/css-opacity caniuse
/// @link http://www.w3.org/TR/css3-color/#transparency spec
///
/// @param {Number} $value [0]
///
/// @output
/// ```css
/// opacity: <value>;
/// filter: alpha(opacity=<value * 100>);
/// ```
///
/// @example
/// .selector {
/// @include x-opacity(0.3);
/// }
///
@mixin x-opacity ($value: 0) {
$value-percentage: $value * 100;
opacity: $value;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=#{$value-percentage})";
filter: alpha(opacity=#{$value-percentage});
}
///
/// Generates `placeholder` content for a given element.
///
/// @author romamatusevich
///
/// @link http://caniuse.com/#feat=css-placeholder caniuse
/// @link http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-placeholder-attribute spec
/// @link https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-placeholder MDN
/// @link http://css-tricks.com/snippets/css/style-placeholder-text css-tricks
///
/// @output
/// ```css
/// &::-webkit-input-placeholder {
/// <content>
/// }
/// &::-moz-placeholder {
/// <content>
/// }
/// &:-ms-input-placeholder {
/// <content>
/// }
/// ```
///
/// @example
/// .selector {
/// @include x-placeholder {
/// color: #bada55;
/// font-weight: bold;
/// }
/// }
///
@mixin x-placeholder {
&::-webkit-input-placeholder {
@content // Chrome, Safari, Opera
}
&::-moz-placeholder {
@content // Firefox 19+
}
&:-ms-input-placeholder {
@content // IE 10+
}
}
///
/// Returns a number without unit.
///
/// Borrowed from https://github.com/zurb/foundation/blob/master/scss/foundation/_functions.scss
///
/// @param {Number} $value
///
/// @returns {Number} - 30px -> 30
///
@function strip-unit($value) {
@return $value / ($value * 0 + 1);
}
///
/// This mixin enables you to use the CSS3 value `rem`, which lets you define
/// property sizes based on the root element's font-size.
///
/// Outputs properties that use rem with a px fallback.
/// It also takes px values and converts them to rem.
///
/// @author drublic
///
/// @link http://caniuse.com/rem caniuse
/// @link http://www.w3.org/TR/css3-values/#relative0 spec
///
/// @param {String} $property
/// @param {List} $values
/// @param {Number} $default-font-size [16px] - optional
///
/// @require {Function} strip-unit
///
/// @output
/// ```css
/// <property>: <parsed value>px;
/// <property>: <parsed value>rem;
/// ```
///
/// @example
/// .selector {
/// @include x-rem(font-size, 1.3);
/// @include x-rem(padding, 20px);
/// }
///
@mixin x-rem ($property, $values, $main-font-size: 16px) {
// Empty list for all values in px
$px-values: ();
$rem-values: ();
// Iterate over entries
@each $value in $values {
// If the value is zero or of a type that doesn’t need conversion, return the value untouched
@if index(auto inherit initial none 0, $value) or type-of($value) != "number" {
$px-values: append($px-values, $value);
$rem-values: append($rem-values, $value);
// Otherwise convert it properly
} @else {
$unit: unit($value);
@if $unit == 'px' {
$px-values: append($px-values, #{strip-unit($value)} * 1px );
$rem-values: append($rem-values, (strip-unit($value) / strip-unit($main-font-size) * 1rem));
} @else {
$px-values: append($px-values, ($value * $main-font-size) );
$rem-values: append($rem-values, #{$value} * 1rem);
}
}
}
// Return the property and its list of converted values
#{$property}: #{$px-values};
#{$property}: #{$rem-values};
}
///
/// Sass-mixin for CSS property `tab-size`, generates cross-browser-compatible
/// `tab-size` output.
///
/// @author drublic
///
/// @link http://caniuse.com/css3-tabsize caniuse
/// @link http://dev.w3.org/csswg/css-text/#tab-size1 spec
///
/// @param {Number} $value [4] - optional
///
/// @output
/// ```css
/// -moz-tab-size: <value>;
/// tab-size: <value>;
/// ```
///
/// @example
/// .selector {
/// @include x-tab-size(4);
/// }
///
@mixin x-tab-size ($value: 4) {
-moz-tab-size: $value;
tab-size: $value;
}