Open In App

Bulma CSS Mixins

In this article, we will know about Bulma CSS Mixins. Bulma CSS Mixins are the mixins that help the users to add CSS rules 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 CSS mixins as given below;



For using mixins, there is no specific predefined class given by Bulma rather we create our own classes and style them using SASS mixins.

 



Syntax:

.bulma-[CSS Mixin Name]-mixin {
       @include [CSS 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 Block Mixins.




<!DOCTYPE html>
<html lang="en">
    
<head>
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <link rel="stylesheet"
          href="gfgstyles.css">
</head>
    
<body>
    <div class="content container has-text-centered">
        <h1 class="title has-text-success">
          GeekforGeeks
        </h1>
        <h1 class="subtitle">Bulma Block Mixin</h1>
    </div>
    
    <div class="container subtitle 
                has-text-centered 
                has-background-success">
        <h1 class="bulma-block-mixin">
          This header has a spacing of margin-bottom.
        </h1>
        <h1 class="bulma-block-mixin">
          This header too.
        </h1>
        <h1 class="bulma-block-mixin">
          This does not because it's the last header/child.
        </h1>
    </div>
</body>
    
</html>




@mixin block($spacing) {
    margin-bottom: $spacing;
}
    
.bulma-block-mixin {
    @include block(4rem);
}

Output:

 

Example 2: Below example illustrates the Bulma overflow touch mixin.




<!DOCTYPE html>
<html lang="en">
    
<head>
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <link rel="stylesheet"
          href="gfgstyles.css">
</head>
    
<body>
    <div class="content container has-text-centered">
        <h1 class="title has-text-success">
          GeekforGeeks
        </h1>
        <h2 class="subtitle">
          Bulma Overflow touch Mixin
        </h2>
    </div>
    
    <div class="container">
        <div class="touch-scroll-mixin">
            <p class="touch is-4">
                Welcome to GeekforGeeks. Find programming
                articles, tutorials, and more.
            </p>
        </div>
    </div>
</body>
    
</html>




@mixin overflow-touch() {
    -webkit-overflow-scrolling: touch;
    width: 100%;
    overflow: auto;
}
    
.touch {
    width: 200%;
    border: 2px solid #eaf2f4;
    padding: 10px;
}
    
.touch-scroll-mixin {
    @include overflow-touch();
}

Output:

 

Example 3: Below example illustrates the Bulma reset mixin in a Bulma button.




<!DOCTYPE html>
<html lang="en">
    
<head>
    <link rel="stylesheet" 
          href=
    <script src=
    </script>
    <link rel="stylesheet"
          href="gfgstyles.css">
</head>
    
<body>
    <div class="content container has-text-centered">
        <div class="title is-1 has-text-success">
            GeekforGeeks</div>
        <div class="title is-3">Bulma Reset Mixins</div>
    
        <div>
            <h4 class="button is-success">
              Bulma default button
            </h4>
            <h4 class="button bulma-reset-mixin">
              Bulma reset button
            </h4>
        </div>
    
    </div>
</body>
    
</html>




@mixin reset() {
    appearance: none;
    background: 0 0;
    border: none;
    font-family: inherit;
    font-size: 1em;
    margin: 0;
    padding: 0;
}
    
.bulma-reset-mixin {
    @include reset;
}

Output:

 

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


Article Tags :