2021-09-19 00:23:53 +00:00
---
2024-03-21 16:11:54 +00:00
title: Bulma Sass Responsive Mixins
layout: docs
theme: sass
doc-tab: sass
2021-09-19 22:36:15 +00:00
doc-subtab: responsive-mixins
2021-09-19 00:23:53 +00:00
breadcrumb:
2024-03-21 16:11:54 +00:00
- home
- documentation
- sass
- sass-responsive-mixins
2021-09-19 00:23:53 +00:00
---
2021-09-19 22:36:15 +00:00
< div class = "content" >
< p >
2022-06-25 18:09:23 +00:00
Bulma is < strong > responsive by default< / strong > . < a href = "{{ site.url}}/documentation/overview/responsiveness/" > Learn more about Bulma's responsiveness< / a > .
2021-09-19 22:36:15 +00:00
< / p >
2021-09-19 23:34:41 +00:00
< / div >
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="from() and until() mixins" %}
2021-09-19 23:34:41 +00:00
< 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 >
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet-inline.html content="@mixin from($breakpoint)" %} to target devices with a screen < em > wider< / em > than or equal to the breakpoint
2021-09-19 23:34:41 +00:00
< / li >
< li >
2024-03-21 16:11:54 +00:00
{% include docs/elements/snippet-inline.html content="@mixin until($breakpoint)" %} to target devices with a screen < em > narrower< / em > than the breakpoint
2021-09-19 23:34:41 +00:00
< / li >
< / ul >
< p > Their usage is very simple:< / p >
< / div >
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor-bis.html name="from()" %}
2021-09-19 23:34:41 +00:00
< 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 >
2024-03-21 16:11:54 +00:00
{% highlight sass %}@use "bulma/sass/utilities/mixins";
.my-element {
2021-09-19 23:34:41 +00:00
background: red;
2024-03-21 16:11:54 +00:00
@include mixins.from(1280px) {
2021-09-19 23:34:41 +00:00
background: blue;
}
}{% endhighlight %}
< p class = "title is-6" > CSS output< / p >
2021-09-19 22:36:15 +00:00
2021-09-19 23:34:41 +00:00
{% 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 >
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor-bis.html name="until()" %}
2021-09-19 23:34:41 +00:00
< 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 >
2024-03-21 16:11:54 +00:00
{% highlight sass %}@use "bulma/sass/utilities/mixins";
$breakpoint: 1280px;
2021-09-19 23:34:41 +00:00
.my-element {
2024-03-21 16:11:54 +00:00
@include mixins.until($breakpoint) {
2021-09-19 23:34:41 +00:00
background: green;
}
2024-03-21 16:11:54 +00:00
@include mixins.from($breakpoint) {
2021-09-19 23:34:41 +00:00
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 >
2024-03-21 16:11:54 +00:00
{% include docs/elements/anchor.html name="Named mixins" %}
2021-09-19 23:34:41 +00:00
< 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" >
2024-03-21 16:11:54 +00:00
While you could use the mixins {% include docs/elements/snippet-inline.html content="@include mixins.from()" %} and {% include docs/elements/snippet-inline.html content="@include mixins.until()" %}, Bulma provides < strong > quick shortcuts< / strong > with < strong > 11 named mixins< / strong > .
2021-09-19 23:34:41 +00:00
< / 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 >
2021-09-19 22:36:15 +00:00
< / div >
{% capture inc-mobile %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.mobile {
2021-09-19 22:36:15 +00:00
// Styles applied
// below $tablet
}
{% endcapture %}
{% capture inc-tablet %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.tablet {
2021-09-19 22:36:15 +00:00
// Styles applied
// above $tablet
}
{% endcapture %}
{% capture inc-tablet-only %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.tablet-only {
2021-09-19 22:36:15 +00:00
// Styles applied
// between $tablet
// and $desktop
}
{% endcapture %}
{% capture inc-desktop-only %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.desktop-only {
2021-09-19 22:36:15 +00:00
// Styles applied
// between $desktop
// and $widescreen
}
{% endcapture %}
{% capture inc-widescreen-only %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.widescreen-only {
2021-09-19 22:36:15 +00:00
// Styles applied
// between $widescreen
// and $fullhd
}
{% endcapture %}
{% capture inc-desktop %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.desktop {
2021-09-19 22:36:15 +00:00
// Styles applied
// above $desktop
}
{% endcapture %}
{% capture inc-widescreen %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.widescreen {
2021-09-19 22:36:15 +00:00
// Styles applied
// above $widescreen
}
{% endcapture %}
{% capture inc-fullhd %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.fullhd {
2021-09-19 22:36:15 +00:00
// Styles applied
// above $fullhd
}
{% endcapture %}
{% capture inc-touch %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.touch {
2021-09-19 22:36:15 +00:00
// Styles applied
// below $desktop
}
{% endcapture %}
{% capture inc-until-widescreen %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.until-widescreen {
2021-09-19 22:36:15 +00:00
// Styles applied
// below $widescreen
}
{% endcapture %}
{% capture inc-until-fullhd %}
2024-03-21 16:11:54 +00:00
@use "bulma/sass/utilities/mixins";
@include mixins.until {
2021-09-19 22:36:15 +00:00
// 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 >