Open In App

Bulma Direction Mixins

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:



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.




<!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>




$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.




<!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>




$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 


Article Tags :