UNPKG

3.35 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5/// Hide an element by default, only displaying it above a certain screen size.
6/// @param {Keyword} $size - Breakpoint to use. **Must be a breakpoint defined in `$breakpoints`.**
7@mixin show-for($size) {
8 $size: map-get($breakpoints, $size);
9 $size: -zf-bp-to-em($size) - (1 / 16);
10
11 @include breakpoint($size down) {
12 display: none !important;
13 }
14}
15
16/// Hide an element by default, only displaying it within a certain breakpoint.
17/// @param {Keyword} $size - Breakpoint to use. **Must be a breakpoint defined in `$breakpoints`.**
18@mixin show-for-only($size) {
19 $lower-bound-size: map-get($breakpoints, $size);
20 $upper-bound-size: -zf-map-next($breakpoints, $size);
21
22 // more often than not this will be correct, just one time round the loop it won't so set in scope here
23 $lower-bound: -zf-bp-to-em($lower-bound-size) - (1 / 16);
24 // test actual lower-bound-size, if 0 set it to 0em
25 @if strip-unit($lower-bound-size) == 0 {
26 $lower-bound: -zf-bp-to-em($lower-bound-size);
27 }
28
29 @if $upper-bound-size == null {
30 @media screen and (max-width: $lower-bound) {
31 display: none !important;
32 }
33 }
34 @else {
35 $upper-bound: -zf-bp-to-em($upper-bound-size);
36
37 @media screen and (max-width: $lower-bound), screen and (min-width: $upper-bound) {
38 display: none !important;
39 }
40 }
41}
42
43
44/// Show an element by default, and hide it above a certain screen size.
45/// @param {Keyword} $size - Breakpoint to use. **Must be a breakpoint defined in `$breakpoints`.**
46@mixin hide-for($size) {
47 @include breakpoint($size) {
48 display: none !important;
49 }
50}
51
52/// Show an element by default, and hide it above a certain screen size.
53/// @param {Keyword} $size - Breakpoint to use. **Must be a breakpoint defined in `$breakpoints`.**
54@mixin hide-for-only($size) {
55 @include breakpoint($size only) {
56 display: none !important;
57 }
58}
59
60@mixin foundation-visibility-classes {
61 // Basic hiding classes
62 .hide {
63 display: none !important;
64 }
65
66 .invisible {
67 visibility: hidden;
68 }
69
70 // Responsive visibility classes
71 @each $size in $breakpoint-classes {
72 @if $size != $-zf-zero-breakpoint {
73 .hide-for-#{$size} {
74 @include hide-for($size);
75 }
76
77 .show-for-#{$size} {
78 @include show-for($size);
79 }
80 }
81
82 .hide-for-#{$size}-only {
83 @include hide-for-only($size);
84 }
85
86 .show-for-#{$size}-only {
87 @include show-for-only($size);
88 }
89 }
90
91 // Screen reader visibility classes
92 // Need a "hide-for-sr" class? Add aria-hidden='true' to the element
93 .show-for-sr,
94 .show-on-focus {
95 @include element-invisible;
96 }
97
98 // Only display the element when it's focused
99 .show-on-focus {
100 &:active,
101 &:focus {
102 @include element-invisible-off;
103 }
104 }
105
106 // Landscape and portrait visibility
107 .show-for-landscape,
108 .hide-for-portrait {
109 display: block !important;
110
111 @include breakpoint(landscape) {
112 display: block !important;
113 }
114
115 @include breakpoint(portrait) {
116 display: none !important;
117 }
118 }
119
120 .hide-for-landscape,
121 .show-for-portrait {
122 display: none !important;
123
124 @include breakpoint(landscape) {
125 display: none !important;
126 }
127
128 @include breakpoint(portrait) {
129 display: block !important;
130 }
131 }
132}