Throughout the codebase, Bulma uses Sass mixins to <strong>enhance</strong> and facilitate the CSS output. While these mixins are mainly used within the context of Bulma, they are of course available for you to <strong>re-use</strong> in your own projects.
</p>
</div>
{% include elements/anchor.html name="Element Mixins" %}
The <code>hamburger()</code> mixin creates a 16x16px set of <strong>3 horizontal bars</strong> grouped within square. The dimensions of this square are defined by the <code>$dimensions</code> parameter.
</p>
</div>
{% highlight sass %}.bulma-hamburger-mixin {
@include hamburger(2.5rem);
}{% endhighlight %}
{% capture hamburger %}
<buttonclass="bulma-hamburger-mixin">
<span></span>
<span></span>
<span></span>
</button>
{% endcapture %}
{% include elements/snippet.html content=hamburger %}
The <code>delete()</code> mixin creates a 20x20px circle containing a <strong>cross</strong>. It comes with 3 modifiers: <code>is-small</code>, <code>is-medium</code> and <code>is-large</code>.
{% include elements/anchor-bis.html name="Font Awesome container" %}
<divclass="content">
<p>
The <code>fa()</code> mixin creates a <strong>square inline-block element</strong>, ideal for containing a Font Awesome icon, or any other type of icon font.
<br>
The first <code>$size</code> parameter defines the icon font size.
<br>
The second <code>$dimensions</code> parameter defines the dimensions of the square container.
</p>
</div>
{% highlight sass %}.bulma-fa-mixin {
@include fa(1rem, 2rem);
background-color: lavender; // For demo purposes
}{% endhighlight %}
{% capture fa %}
<spanclass="bulma-fa-mixin">
<iclass="fas fa-thumbs-up"></i>
</span>
{% endcapture %}
{% include elements/snippet.html content=fa %}
<!---->
{% include elements/anchor.html name="CSS Mixins" %}
<pclass="block">
These mixins add <strong>CSS rules</strong> to the element.
</p>
<!---->
{% include elements/anchor-bis.html name="Block" %}
{% include elements/snippet.html content=overlay %}
<!---->
{% include elements/anchor-bis.html name="Center" %}
<divclass="content">
<p>
The <code>center()</code> mixin allows you to absolutely position an element with <strong>fixed dimensions</strong> at the <strong>center</strong> of its closest positioned ancestor.
The value of the <code>$width</code> parameter should be the width of the element the mixin is applied on.
<br>
Unless the element has square dimensions, the second parameter <code>$height</code> is required and its value should be the height of the element the mixin is applied on.
{% include elements/anchor-bis.html name="Unselectable" %}
<divclass="content">
<p>
The <code>unselectable()</code> mixin makes an element not selectable. This is to prevent the text to be selected when double-clicked.
</p>
</div>
{% highlight sass %}.bulma-unselectable-mixin {
@include unselectable;
}{% endhighlight %}
{% capture unselectable %}
<p>This text is selectable.</p>
<pclass="bulma-unselectable-mixin">This text is not selectable.</p>
{% endcapture %}
{% include elements/snippet.html content=unselectable %}
<!---->
{% include elements/anchor-bis.html name="Overflow Touch" %}
<divclass="content">
<p>
The <code>overflow-touch()</code> mixin add the <code>-webkit-overflow-scrolling: touch;</code> rule to the element.
</p>
</div>
<!---->
{% include elements/anchor.html name="Direction Mixins" %}
{% include elements/anchor-bis.html name="Left-to-right and Right-to-left Mixins" %}
<divclass="content">
<p>
Bulma has a global <code>$rtl</code> flag, which allows the framework to output a Right-to-left version of the CSS. By default, this flag's value is set to <code>false</code>. This means the framework output a Left-to-right version.
</p>
<p>
The mixins <code>@mixin ltr</code> and <code>@mixin rtl</code> are here to output CSS rules based on the value of <code>$rtl</code>:
</p>
<ul>
<li>
if <code>$rtl: true</code>, <code>@include ltr</code> outputs nothing
</li>
<li>
if <code>$rtl: false</code>, <code>@include rtl</code> outputs nothing
</li>
</ul>
<p>
This is useful for properties that are specific to the side of an element.
</p>
</div>
{% highlight sass %}.bulma-ltr-rtl-mixin {
background-color: lightgreen;
padding: 0.5em 1em;
border: 1px solid seagreen;
margin-right: -1px;
&:first-child {
@include ltr {
border-bottom-left-radius: 0.5em;
border-top-left-radius: 0.5em;
}
@include rtl {
border-bottom-right-radius: 0.5em;
border-top-right-radius: 0.5em;
}
}
&:last-child {
@include ltr {
border-bottom-right-radius: 0.5em;
border-top-right-radius: 0.5em;
}
@include rtl {
border-bottom-left-radius: 0.5em;
border-top-left-radius: 0.5em;
}
}
}{% endhighlight %}
{% capture ltr-rtl %}
<divstyle="display: flex;">
<spanclass="bulma-ltr-rtl-mixin">One</span>
<spanclass="bulma-ltr-rtl-mixin">Two</span>
<spanclass="bulma-ltr-rtl-mixin">Three</span>
</div>
{% endcapture %}
{% include elements/snippet.html content=ltr-rtl %}
<!---->
{% include elements/anchor-bis.html name="LTR Position" %}
<divclass="content">
<p>
The <code>ltr-position()</code> mixin is a quick way to switch between <code>left</code> and <code>right</code> CSS properties when dealing with positioned elements.
<br>
The first <code>$spacing</code> parameter defines the value of the offset, whether it's right or left.
<br>
The second <code>$right</code> parameter defines if the property outputs <code>right</code> (default) or <code>left</code>.
</p>
<p>
Here is what the output looks like with a <code>$spacing</code> parameter set to <code>1rem</code>:
<p>Cras mattis consectetur purus sit amet fermentum. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Curabitur blandit tempus porttitor. Maecenas faucibus mollis interdum.</p>
</div>
{% endcapture %}
{% include elements/snippet.html content=ltr-position %}
<!---->
{% include elements/anchor-bis.html name="LTR Property" %}
<divclass="content">
<p>
The <code>ltr-property()</code> mixin works like the <code>ltr-position()</code> mixin but allows you to choose <strong>which CSS property</strong> to set. The mixin will append <code>-right</code> or <code>-left</code> to that property. This is especially useful for <code>margin</code> and <code>padding</code>.
<br>
The first <code>$property</code> parameter which property you want to "flip" left and right.
<br>
The second <code>$spacing</code> parameter defines the value of the offset, whether it's right or left.
<br>
The third <code>$right</code> parameter defines if the property outputs <code>right</code> (default) or <code>left</code>.
</p>
<p>
Here is what the output looks like with a <code>$spacing</code> parameter set to <code>1rem</code>:
<p>Cras mattis consectetur purus sit amet fermentum. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Curabitur blandit tempus porttitor. Maecenas faucibus mollis interdum.</p>