Open In App

Bulma Direction Mixins

Last Updated : 07 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will know about Bulma Direction Mixins. Bulma Direction Mixins are the mixins that help the users to add left or right alignment to the HTML element.

Bulma uses Sass mixins to create the CSS output and they are mainly used within the context of the Bulma framework. Bulma has various different types of Direction mixins as given below:

  • Left-to-right and Right-to-left Mixins: These Direction mixins are used to create a down-facing arrow.
  • LTR Position: These Direction mixins are used to quickly switch between left and right CSS properties when dealing with positioning elements.
  • LTR Property: These Direction mixins are used not only to quickly switch between left and right CSS properties. But also allows users to set the positioning CSS property.

Syntax:

.bulma-[Direction  Mixin Name]-mixin {
     @include [Direction  Mixin Name](params);
}

Note: You must know the implementation of SASS mixins for the below examples. Please see the pre-requisite given on the link and then implement the below code.

Example 1: Below example illustrates the Bulma Directions Mixins.

HTML




<!DOCTYPE html>
<html lang="en">
    
<head>
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <link rel="stylesheet"
          href="css/gfgstyles.css">
</head>
    
<body class="content container has-text-centered">
    <div>
        <h1 class="title is-1 has-text-success">
              GeekforGeeks
        </h1>
        <h1 class="subtitle">Bulma Direction Mixins</h1>
    </div>
    
    <div>
          <span class="bulma-ltr-rtl-mixin">Geek1</span>
          <span class="bulma-ltr-rtl-mixin">Geek2</span>
          <span class="bulma-ltr-rtl-mixin">Geek3</span>
    </div>
</body>
    
</html>


CSS




$rtl: false;
$ltr: true;
  
@mixin ltr() {
    @if not $rtl {
        @content;
    }
}
  
@mixin rtl() {
    @if $rtl {
        @content;
    }
}
  
.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;
        }
    }
}


Output:

 

Example 2: Below is another example to illustrate the Bulma Directions Mixins.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet" href=
    <script src=
    </script>
    <link rel="stylesheet" href="css/gfgstyles.css">
</head>
  
<body class="content container has-text-centered">
    <div>
        <h1 class="title is-1 has-text-success">
            GeekforGeeks
        </h1>
        <h1 class="subtitle">
            Bulma Direction Mixins
        </h1>
    </div>
  
    <div class="bulma-ltr-position-mixin-parent">
        <img class="bulma-ltr-position-mixin" 
            height="120" width="120"
            src=
        <p>
            GeeksforGeeks | A computer 
            science portal for geeks.
        </p>
    </div>
</body>
  
</html>


CSS




$rtl: false;
$ltr: true;
  
@mixin ltr-position($spacing, $right: true) {
    $normal: if($right, "right", "left");
    $opposite: if($right, "left", "right");
  
    @if $rtl {
        #{$opposite}: $spacing;
    }
  
    @else {
        #{$normal}: $spacing;
    }
}
  
.bulma-ltr-position-mixin {
    @include ltr-position(1rem, false);
    border-radius: 0.25em;
    position: absolute;
    top: 1rem;
}


Output:

 

Reference: https://bulma.io/documentation/utilities/mixins/#direction-mixins 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads