Welcome to mirror list, hosted at ThFree Co, Russian Federation.

responsive-mixins.html « utilities « documentation « docs - github.com/jgthms/bulma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b71fccacf0aa4fd3f030c8f0868988b00ffffe3 (plain)
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
---
title: Responsive Mixins
layout: documentation
doc-tab: utilities
doc-subtab: responsive-mixins
fullmain: true
breadcrumb:
- home
- documentation
- utilities
- utilities-responsive-mixins
---

<div class="content">
  <p>
    Bulma is <strong>responsive by default</strong>. <a href="{{ site.url}}/overview/responsiveness/">Learn more about Bulma's responsiveness</a>.
  </p>
</div>

{% include elements/anchor.html name="from() and until() mixins" %}

<div class="content">
  <p>
    Responsiveness in CSS is based on <strong>media queries</strong> (see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries" target="_blank">MDN documentation</a>).
  </p>

  <p>
    Bulma provides <strong>2 useful responsive mixins:</strong>
  </p>

  <ul>
    <li>
      {% include elements/snippet-inline.html content="@mixin from($breakpoint)" %} to target devices with a screen <em>wider</em> than or equal to the breakpoint
    </li>
    <li>
      {% include elements/snippet-inline.html content="@mixin until($breakpoint)" %} to target devices with a screen <em>narrower</em> than the breakpoint
    </li>
  </ul>

  <p>Their usage is very simple:</p>
</div>

{% include elements/anchor-bis.html name="from()" %}

<div class="content">
  <p>
    The <code>from()</code> mixin has a single parameter which sets the <strong>screen width</strong> from which the styles it contains will be applied:
  </p>
</div>

<p class="title is-6">Sass source</p>

{% highlight sass %}.my-element {
  background: red;

  @include from(1280px) {
    background: blue;
  }
}{% endhighlight %}

<p class="title is-6">CSS output</p>

{% highlight css %}.my-element {
  background: red;
}

@media screen and (min-width: 1280px) {
  .my-element {
    background: blue;
  }
}{% endhighlight %}

<div class="content">
  <p>
    For screens with a width of 1279px or less, the element's background will be <strong style="color: red;">red</strong>.
    <br>
    For screens 1280px-wide or more, the element's background will be <strong style="color: blue;">blue</strong>.
  </p>
</div>

{% include elements/anchor-bis.html name="until()" %}

<div class="content">
  <p>
    The <code>until()</code> mixin has a single parameter which sets the <strong>screen width (minus <code>1px</code>)</strong> until which the styles it contains will be applied.
  </p>

  <p>
    This means that if you set a value of <code>1280px</code>, the styles will be applied on a screen width of <code>1279px</code> but <strong>not</strong> on a screen width of <code>1280px</code>.
  </p>

  <p>
    The reason for this <strong>1px offset</strong> is to allow you to use both <code>from()</code> and <code>until()</code> with the <strong>same breakpoint value</strong>. This leaves <strong>no gap</strong> between the 2 sets of rules.
  </p>
</div>

<p class="title is-6">Sass source</p>

{% highlight sass %}$breakpoint: 1280px;

.my-element {
  @include until($breakpoint) {
    background: green;
  }

  @include from($breakpoint) {
    background: orange;
  }
}{% endhighlight %}

<p class="title is-6">CSS output</p>

{% highlight css %}@media screen and (max-width: 1279px) {
  .my-element {
    background: green;
  }
}

@media screen and (min-width: 1280px) {
  .my-element {
    background: orange;
  }
}{% endhighlight %}

<div class="content">
  <p>
    For screens with a width of 1279px or less, the element's background will be <strong style="color: green;">green</strong>.
    <br>
    For screens 1280px-wide or more, the element's background will be <strong style="color: orange;">orange</strong>.
  </p>
</div>

{% include elements/anchor.html name="Named mixins" %}

<div class="content">
  <p>
    By having <strong>4 breakpoints</strong> and supporting <strong>5 screen sizes</strong>, Bulma can support a lot of different setups.
  </p>
</div>

<div class="content">
  While you could use the mixins {% include elements/snippet-inline.html content="@include from()" %} and {% include elements/snippet-inline.html content="@include until()" %}, Bulma provides <strong>quick shortcuts</strong> with <strong>11 named mixins</strong>.
</div>

<div class="content">
  <p>
      These <strong>responsive mixins</strong> are named after the screen sizes and breakpoints used in Bulma, so that you can use them to create a <strong>responsive designs</strong>:
  </p>
</div>

{% capture inc-mobile %}
@include mobile {
  // Styles applied
  // below $tablet
}
{% endcapture %}

{% capture inc-tablet %}
@include tablet {
  // Styles applied
  // above $tablet
}
{% endcapture %}

{% capture inc-tablet-only %}
@include tablet-only {
  // Styles applied
  // between $tablet
  // and $desktop
}
{% endcapture %}

{% capture inc-desktop-only %}
@include desktop-only {
  // Styles applied
  // between $desktop
  // and $widescreen
}
{% endcapture %}

{% capture inc-widescreen-only %}
@include widescreen-only {
  // Styles applied
  // between $widescreen
  // and $fullhd
}
{% endcapture %}

{% capture inc-desktop %}
@include desktop {
  // Styles applied
  // above $desktop
}
{% endcapture %}

{% capture inc-widescreen %}
@include widescreen {
  // Styles applied
  // above $widescreen
}
{% endcapture %}

{% capture inc-fullhd %}
@include fullhd {
  // Styles applied
  // above $fullhd
}
{% endcapture %}

{% capture inc-touch %}
@include touch {
  // Styles applied
  // below $desktop
}
{% endcapture %}

{% capture inc-until-widescreen %}
@include until-widescreen {
  // Styles applied
  // below $widescreen
}
{% endcapture %}

{% capture inc-until-fullhd %}
@include until {
  // Styles applied
  // below $fullhd
}
{% endcapture %}

<div class="table-container">
  <table class="table is-bordered">
    <thead>
      <tr>
        {% for breakpoint_hash in site.data.breakpoints %}
          {% assign breakpoint = breakpoint_hash[1] %}
          <th style="width: 20%;">
            {{ breakpoint.name }}<br>
            {% if breakpoint.id == 'mobile' %}
              Up to <code>{{ breakpoint.to }}px</code>
            {% elsif breakpoint.id == 'fullhd' %}
              <code>{{ breakpoint.from }}px</code> and above
            {% else %}
              Between <code>{{ breakpoint.from }}px</code> and <code>{{ breakpoint.to }}px</code>
            {% endif %}
          </th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          {% highlight sass %}{{ inc-mobile }}{% endhighlight %}
        </td>
        <td colspan="4">
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td>
          <p class="notification">-</p>
        </td>
        <td colspan="4">
          {% highlight sass %}{{ inc-tablet }}{% endhighlight %}
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <p class="notification">-</p>
        </td>
        <td colspan="3">
          {% highlight sass %}{{ inc-desktop }}{% endhighlight %}
        </td>
      </tr>
      <tr>
        <td colspan="3">
          <p class="notification">-</p>
        </td>
        <td colspan="2">
          {% highlight sass %}{{ inc-widescreen }}{% endhighlight %}
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <p class="notification">-</p>
        </td>
        <td>
          {% highlight sass %}{{ inc-fullhd }}{% endhighlight %}
        </td>
      </tr>
      <tr>
        <td>
          <p class="notification">-</p>
        </td>
        <td>
          {% highlight sass %}{{ inc-tablet-only }}{% endhighlight %}
        </td>
        <td colspan="3">
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <p class="notification">-</p>
        </td>
        <td>
          {% highlight sass %}{{ inc-desktop-only }}{% endhighlight %}
        </td>
        <td colspan="2">
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td colspan="3">
          <p class="notification">-</p>
        </td>
        <td>
          {% highlight sass %}{{ inc-widescreen-only }}{% endhighlight %}
        </td>
        <td>
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          {% highlight sass %}{{ inc-touch }}{% endhighlight %}
        </td>
        <td colspan="3">
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td colspan="3">
          {% highlight sass %}{{ inc-until-widescreen }}{% endhighlight %}
        </td>
        <td colspan="2">
          <p class="notification">-</p>
        </td>
      </tr>
      <tr>
        <td colspan="4">
          {% highlight sass %}{{ inc-until-fullhd }}{% endhighlight %}
        </td>
        <td colspan="1">
          <p class="notification">-</p>
        </td>
      </tr>
    </tbody>
  </table>
</div>

{% assign or_link = site.data.links.by_id['overview-responsiveness'] %}

<div class="content">
  <p>
    Learn more about <a href="{{ site.url }}{{ or_link.path }}">Bulma responsiveness</a>.
  </p>
</div>