Customize Bulma Variables in a Nuxt Component

Trying to adjust the $navbar-height value through a mounted function in a Nuxt component has been successful overall, but I'm encountering issues with overriding Bulma variables.

I included Bulma in the Nuxt configuration:

modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios',
    // Doc:https://github.com/nuxt-community/modules/tree/master/packages/bulma
    '@nuxtjs/bulma',
    '@nuxtjs/font-awesome'
  ]

Furthermore, I made changes to some variables in my main.scss file:

@import '~bulma/sass/utilities/initial-variables';
@import '~bulma/sass/utilities/mixins';
@import '~bulma/sass/utilities/functions';

$primary: #3dccc8;
$danger: #dc5222;
$navbar-height: 5rem;
$navbar-item-img-max-height: 3rem;

@import '~bulma/bulma';

The main.scss file was also added to the Nuxt Config:

css: [
    { src: '~assets/css/main.scss', lang: 'scss' }
  ],

Despite these configurations, attempting to modify the variable in a component doesn't yield any results.

Below is the function being used:

mounted() {
    this.$nextTick(function(){
      window.addEventListener("scroll", function(){
        var navbar = document.getElementById("nav")
        var nav_classes = navbar.classList
        if(document.documentElement.scrollTop >= 10) {
          if (nav_classes.contains("shrink") === false) {
            nav_classes.toggle("shrink");
            console.log(nav_classes)
          }
        }
        else {
          if (nav_classes.contains("shrink") === true) {
            nav_classes.toggle("shrink");
          }
        }
      })
    })
  }

Answer №1

To remove @nuxtjs/bulma from your nuxt.config.js file, simply comment it out and instead import main.scss. Your updated code snippet will look like this:

@import '~bulma/sass/utilities/initial-variables'; 
@import '~bulma/sass/utilities/functions';

// customize styles

$black: #343434; 
$family-sans-serif: Avenir, sans-serif;

@import '~bulma';

This way, you can keep the original Bulma package without having to uninstall nuxt-bulma and reinstalling a regular one.

Answer №2

If you're looking to personalize bulma, it's best to steer clear of using @nuxtjs/bulma. This particular package simply injects the standard prebuilt bulma css into your project.

Instead, the ideal approach is to construct bulma within your project.

To begin, make sure to install the node-sass and sass-loader packages:

npm install sass-loader node-sass webpack --save-dev

Next, include the following entry in your nuxt.config.js file:

css: [{src: '@/assets/sass/app.sass', lang: 'sass' }],

In the assets/sass/app.sass file, insert the following:

@import "~bulma/sass/utilities/_all"; // -- (1)
$navbar-height: 40px // this is where you can customize the variable
@import "~bulma"; // now load bulma

The inclusion of line (1) is optional, but highly recommended as it provides access to utility functions that facilitate customizing the variables you desire.

Answer №3

Latest Update 2020

I recently grabbed the SCSS file from .

// Including Bulma's core
@import "~bulma/sass/utilities/_all";

// Defining your color palette
$primary: #8c67ef;
$primary-light: findLightColor($primary);
$primary-dark: findDarkColor($primary);
$primary-invert: findColorInvert($primary);

// Various other styles and variables can be found here.

// Importing Bulma and Buefy styles
@import "~bulma";
@import "~buefy/src/scss/buefy";

Next, I placed it in the assets directory under the name style.scss, though you can use any name you prefer.

Edit the variables and styles to suit your needs.

Following that, I installed sass-loader using the command:

yarn add node-sass sass-loader -D

I linked my custom SCSS file in the default.vue file like so:

<style lang="scss">
  @import '~assets/style.scss';
</style>

*Remember to restart to apply the changes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Make sure to maintain the hover effect even after clicking

How can I make my div retain the hover effect even after clicking on it? Here is the code snippet: #work_btn{ position:absolute; top:60%; left:60px; color:grey; background: -webkit-linear-gradient(0deg, #ff956c, #ff3644); -webkit-background-clip: text ...

Change the name of the state in Vue mapState

I have a specific situation in my computed where I need to track two different "loading" states. Is there a method to include an alias for the second state using this syntax? computed: { ...mapState('barcodes', ['barcodes', ' ...

CSS: The Ultimate Guide to Concealing the Second Row in a Table

I have a single table in my code: <table> <tr><td>sample data 1</td></tr> <tr><td>sample data 2</td></tr> <tr><td>sample data 3</td></tr> <tr><td>sample data 4</t ...

Would it be possible for me to adjust the CSS to center the sections?

I'm facing an issue with the layout of my website at . At the bottom, there is a navigation menu and three boxes with images. However, they are currently left-aligned instead of centered. Can anyone suggest CSS code that I can use to center them? Her ...

The navigation bar is obscuring the header on my website

I am facing an issue with creating a navigation bar that covers up the header text. I tried adjusting the margins to fix this problem but ended up moving the header along with the navigation bar. How can I ensure that the navigation bar remains fixed witho ...

The CSS show and hide feature is effective across all browsers except for Safari. What steps can be taken to address this issue

My toggle trigger works perfectly in Chrome, but I'm having trouble getting it to work in Safari. Any suggestions? <a href='#show'class='show'>see more --></a> <a href='#hide'class='hide&apos ...

Is there a way to incorporate a Vue component into a custom editor for a Kendo grid?

I am working with a column in a kendo grid that looks like this: <kendo-grid-column :field="'qrcode'" :title="'qrcode'" :width="200" :editor="qrcodeEditor" ></kendo-grid-column> In the documentation on Sett ...

Using JQuery append causes a CSS loading issue with the toggle button

I am currently facing an issue with a toggle button that is not loading the relevant CSS properly when using jQuery to append content. The appended content includes check boxes loaded with the Labelauty jQuery Plugin, which are functioning correctly. Belo ...

Positioning div at the top of the body section

Presently, I have this specific designhttps://i.sstatic.net/U4IT4.png The issue I am facing is with the alignment of the jumbotron (boostrap v5). It is currently centered, but I would like it to be positioned at the very top of the body. I have experiment ...

Tips on resolving issues with form input that is not accepting input on a Mobile device

As a newbie in HTML and CSS, I attempted to design a form with various fields. While the fields work perfectly on larger screens, they do not allow input on smaller screens (mobile devices). I used the Firefox inspect tool to troubleshoot the issue, but c ...

Jquery loader for loading html and php files

My html and php pages contain a significant amount of data which causes them to take a few extra seconds to load from the server. I was wondering if there is a way to implement a "loader animation" for these pages using jquery. The idea is for the loader a ...

Enable the option to customize the icon of the recently activated sidebar menu item

I need help with changing the arrow icon of a menu-item only when it is clicked, without affecting all other menu-items. In the image below, you can see that currently, clicking on any menu-item changes all the arrows. Attached Image //sidebarMenu jQu ...

How can HTML content be stored in a variable using JavaScript?

Today, I delved into JavaScript basics and managed to create a simple HTML page that allows users to add or remove list items. While I am aware that there are more advanced solutions out there, I believe that for my learning process, this accomplishment is ...

Bottom of the page features a crisp white strap

Can someone assist me with the white strap at the bottom of this site found on website? It seems to be powered by wordpress. ...

How to position a "figure" element at the center using CSS creatively (without relying on Div elements)

Struggling with my first website creation, I encountered a challenge in centering three inline-block images using CSS. Despite successfully using the figure tag to title and display the images, I couldn't get them to align horizontally from the cente ...

Pandas now supports exporting data frames to HTML with the added feature of conditional

Is there a way to format a table in pandas where data in each column are styled based on their values, similar to conditional formatting in spreadsheet programs? An example scenario is highlighting significant values in a table: correlation p-value ...

Ensure your div's absolute position is set to the right for a sticky effect

When I set the position of an absolute div like this: left: 700px; It does not move when I resize my browser window. How can I make it float to the right and move left when resizing the window? To illustrate the issue, take a look at this site. Check ou ...

Creating a DIV with vertical scroll-bars exclusively for lengthy paragraphs in HTML: What's the best approach?

I need to display terms and conditions on my website without using a text field or taking up the entire page. Instead, I want to show the text in a specific area with only a vertical scroll bar for users to navigate through the content. Here is the curren ...

Tips on adjusting the color of a link once it has been clicked?

Looking for a link with a specific style? a { color: #999; &:hover { color: #008da0; } &:visited { color: #999; } /* I added this to test if it's gonna fix it, but it didn't */ } Upon clicking the link, it turns blue and remains s ...

Having issues compiling SCSS syntax in a Vue3 app on Vite

I am having difficulties using the scss nesting syntax. _table.scss table { &.table { width: 100%; } } See results in dev tools I included my _table.scss file into main.scss and then imported main.scss into main.js main.scss main.js This is ...