Customize the Vuetify 2.0 sass variable $heading-font-family

I'm currently trying to customize the default variable $heading-font-family in Vuetify 2.0.0-beta.0, but I'm encountering issues with this particular override. Oddly enough, I have been successful in overriding other variables such as $body-font-family, $font-size-root, and $btn-border-radius.

I've consulted the documentation available at for guidance.

In my main.scss file, the modifications I want to make are outlined like so:


// main.scss

@import '~vuetify/src/styles/styles.sass';

// The variables I want to modify
$font-size-root: 16px;
$body-font-family: Arial, sans-serif;
$heading-font-family: 'Open Sans', sans-serif;
$btn-border-radius: 8px;

The template in my .vue file includes the following HTML structure:

// in my vue Template

...
<div class="hello">
  <h1 class="display-1">{{ msg }}</h1>
  <p>Lorem ipsum dolor sit amet...</p>
  <v-btn color="pink" dark>Click me</v-btn>
</div>
...

Upon inspecting the H1 element in the console, I anticipate a font family of 'Open Sans', sans-serif, however it displays "Roboto", sans-serif instead. It seems to be inheriting the default value set for $body-font-family prior to my customization in main.scss.

While the overrides for other variables from my main.scss are functioning correctly, I am puzzled by the behavior related to $heading-font-family. Any insights on what could be going wrong here?

Answer №1

I have attempted all of the suggested solutions without success.

However, I found that by following the instructions at this link, I was able to make it work.

Firstly, create a directory called scss inside the src folder (not /src/styles/scss/ or any other variation). Next, place your new variables values in there.

// /src/scss/variables.scss

$body-font-family: 'Less';
$heading-font-family: $body-font-family;

// Required for modifying core defaults
@import '~vuetify/src/styles/styles.sass';

Answer №2

The issue stems from the use of !important on the font-family property for vuetify typography helper classes.
To resolve this, I made adjustments in my variables.scss file by ensuring the same level of CSS specificity. Since this file is loaded after the vuetify typography helper classes, it effectively overrides them.

Here's a snippet from my variables.scss file:

// All variable changes must occur before @import
$body-font-family: 'Source Sans Pro', sans-serif !important;
// Consider specificity for certain components due to !important in their CSS
html,
body,
.v-application {
  font-family: $body-font-family;
}
// Included all typography helper classes to override css specificity 
.v-application {
    .display-4,
    .display-3,
    .display-2,
    .display-1,
    .headline,
    .title,
    .subtitle-1,
    .subtitle-2,
    .body-1,
    .body-2,
    .caption,
    .overline
    {
        font-family: $body-font-family;
    }
}
@import '~vuetify/src/styles/settings/_variables.scss';

If you encounter any issues, inspect the element defaulting to the Roboto font, check the font-family attribute, identify the causing CSS classes, and add those classes to CSS selectors in the variables.scss file (e.g., .v-application .title)

Answer №3

I encountered a similar issue with $body-font-family, and this was my initial attempt:

$body-font-family : 'ArbitrayFont' !important;
@import '~vuetify/src/styles/styles.sass';

However, after some persistence, I realized that in order to make the vuetify sass variable work, I needed to explicitly assign it to specific elements like so:

 $body-font-family : 'ArbitrayFont' !important;
 html,
body,
.v-application,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: $body-font-family;
}

@import '~vuetify/src/styles/styles.sass';

Answer №4

Greetings! After a period of time, I have aligned all my fonts using the method below.

// src/sass/main.scss
$my-font-family: "Raleway", sans-serif !default;


@import "~vuetify/src/styles/styles.sass";
$body-font-family: $my-font-family;

@import "~vuetify/src/styles/settings/variables";
$body-font-family: $my-font-family;

//Revamp all font styles for headings
$headings: map-merge($headings, (
        'h1': map-merge(
                        map-get($headings, 'h1'),
                        (
                                'font-family': $body-font-family
                        )
        ),
        'h2': map-merge(
                        map-get($headings, 'h2'),
                        (
                                'font-family': $body-font-family
                        )
        ),
        'h3': map-merge(
                        map-get($headings, 'h3'),
                        (
                                'font-family': $body-font-family
                        )
        ),
        'h4': map-merge(
                        map-get($headings, 'h4'),
                        (
                                'font-family': $body-font-family
                        )
        ),
        'h5': map-merge(
                        map-get($headings, 'h5'),
                        ( 'font-family': $body-font-family )
        ),
        'h6': map-merge(
                        map-get($headings, 'h6'),
                        ( 'font-family': $body-font-family )
        ),
        'subtitle-1': map-merge(
                        map-get($headings, 'subtitle-1'),
                        ( 'font-family': $body-font-family)
        ),
        'subtitle-2': map-merge(
                        map-get($headings, 'subtitle-2'),
                        ( 'font-family': $body-font-family)
        ),
        'body-2': map-merge(
                        map-get($headings, 'body-2'),
                        ( 'font-family': $body-font-family)
        ),
        'body-1': map-merge(
                        map-get($headings, 'body-1'),
                        ( 'font-family': $body-font-family)
        ),
        overline: map-merge(
                        map-get($headings, 'overline'),
                        ( 'font-family': $body-font-family)
        ),
        caption: map-merge(
                        map-get($headings, 'caption'),
                        ( 'font-family': $body-font-family)
        )
));

Remember to include the main.scss in your vue.config.js https://vuetifyjs.com/en/customization/sass-variables

Answer №5

According to the Vuetify 2.0 documentation, it is recommended to define default variables before importing any initial styles.

It's important to note that in some cases, adding !important may be necessary for the changes to take effect. Hopefully, this tip proves useful to you.

// src/sass/main.scss

// Any modifications to default variables should be
// specified prior to the initial style import
$body-font-family: 'Source Sans Pro', cursive !important;

$heading-font-family: $body-font-family, cursive !important;

// Essential for altering core defaults
@import '~vuetify/src/styles/styles.sass';

Answer №6

$titles: map-merge(map_get($headings, title), ( title: ( font-family: $title-font) ));

I read in the updated documentation v2.0 that this should work, but unfortunately it's not functioning as expected for me.

Answer №7

For resolving the problem, make sure to place the variables that need modification prior to importing the vuetify styles.sass file. This adjustment should address the issue.

// main.scss

// Variables needing modification
$font-size-root: 16px;
$body-font-family: Arial, sans-serif;
$heading-font-family: 'Open Sans', sans-serif;
$btn-border-radius: 8px;

@import '~vuetify/src/styles/styles.sass';

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

Importing CSS into the styles section of angular.json is no longer feasible with Angular 6

Currently in the process of migrating a project to Angular 6, I'm facing an issue with importing my CSS file within the styles section of angular.json: "styles": [ "./src/styles.css", "./node_modules/primeng/resources/primeng.min.css", ...

Adding custom styles to an unidentified child element in React using Material-UI

When the function below is executed in a loop, I need to include styles for the icon which will be passed as an argument to the function. The icon element will be an unspecified React Material-UI Icon component. const renderStyledCard = (lightMode, headi ...

Embed JavaScript code in the head section of the webpage to guarantee its presence even following a page refresh

We recently obtained an innovative Enterprise Talent Management Solution that is cloud-based. One standout feature allows users to incorporate HTML Widgets with scripts on the primary Welcome Page. The customization options for the Welcome Page UI are qui ...

The error message "TypeError: default is not a function when using vitest" indicates that

I am currently utilizing vitest for unit testing in my Vue application. After writing some tests, I encountered a failure with the error message: 'TypeError: default is not a function'. However, there's no instance of a function called defau ...

What could be causing my Bootstrap (3) grid to not display responsively?

It seems like there may be a simple oversight in my code, as I'm unable to make my Bootstrap grid responsive. I have successfully passed item data through Node and am able to display a grid of item thumbnails with captions in rows of 4. However, when ...

The content in the div is not contained within a border in the css/html

I am struggling with a div wrapper that has a border, but the border is not wrapping around the content and I can't figure out why. Here is my issue on screen: This is what I want it to look like: Below is my HTML code: <div class="event_area_t ...

Rearrange items in a display: contents wrapper using CSS Grid

I'm having trouble positioning descendants in a root grid while they are enclosed in a container with display: contents. The issue I am facing is that one element is not being correctly placed within the grid: .wrapper { width: 80ch; margin: a ...

Choosing between classes and styles for styling components in ReactJS

Can you explain why the call to the classes object works in the code below, rather than to the styles object defined as a const at the beginning? For instance, take a look at this demo: className={classes.button} The above line functions correctly. Howe ...

Repeated Hover Effects on CSS Menu Icons

the webpage I need help with is (issue with general menu drop down) Hello I recently decided to enhance my menu by incorporating icons. I had successfully implemented a drop-down menu using only HTML and CSS, but when I attempted to add icons next to ea ...

The HTML elements may have identical heights, but visually, one appears larger than the other

The size of the "login to enter chat" button seems to be larger than the messageBox div, despite adjusting padding and margins. What could be causing this issue? Any suggestions on how to fix this design glitch? #chatbox { width: 500px; height: ...

Display visual information without requiring the parameters to be filtered beforehand in vue.js

Upon opening my page, I encountered an issue where the graphics appear blank. This is because I set up the callback for generating graphic data through params request. I wish to first fetch the general data when the page opens, and only load with params w ...

Issue with plain CSS animation not functioning in NextJS with Tailwind CSS

I found this amazing animation that I'm trying to implement from this link. After moving some of the animation code to Tailwind for a React Component, I noticed that it works perfectly in Storybook but fails to animate when running in next dev. It si ...

How can the presence of a CSS rule prevent another from being applied?

My attempt to create this HTML file in Chrome posed some challenges: <style> br { }​ [required] { border-width: 3px; border-color: red; } </style> <input required /> The entire content of the file is shown above. However, I noti ...

I am experiencing difficulties with the PHP login form on MAMP as it is not loading properly, displaying only a

Having trouble with php not loading when I open my browser. Here is my database info: MySQL To manage the MySQL Database, you can use phpMyAdmin. If you need to connect to the MySQL Server from your own scripts, use these connection parameters: Host ...

Missing Bootstrap 3 Options Menu trip away

I created a table with 4 columns using the Bootstrap 3 grid system. Instead of utilizing the col-xs-* classes, which work well on mobile devices, I opted for the col-md-* classes. This decision was based on my preference to have larger and more visible ico ...

Issue with Navbar collapse button not displaying items on Bootstrap 4.5.0 in combination with Next.js version 9.4.4

I'm currently working on a nextjs demo project where I'm incorporating bootstrap for styling purposes. The initial setup was straightforward as I installed bootstrap using npm and included it in my app.js. import 'bootstrap/dist/css/bootstra ...

What causes the width of a card to vary between Windows and a Macbook Pro?

Here is the code I have: <div id="app"> <v-app id="inspire"> <v-content> <v-container> <v-card max-width="1000" class="mx-auto" > <v-form v-model="valid"> ...

Creating an Image Link within Nivo Slider

I have been trying to figure out how to make an image a link in NivoSlider. I know that I can use captions to create a link, but I want the actual image to be clickable for better accessibility. I found a similar question on StackOverflow, but it was rela ...

What is the best way to enhance specific sections of Django content by incorporating <span> tags, while maintaining the original paragraph text format?

I am currently in the process of trying to showcase a paragraph of text (content) from django. However, my aim is to incorporate <span class="modify"> into particular words that match pre-defined words located within a referenceList within the paragr ...

Managing and updating arrays in VueJS2: Conditionally push new items and update only if their properties have changed

I am currently facing an issue with my form where each time a user updates a value in an input field, a new array element is created and added to the form results. I'm looking for a way to update the properties of the existing array element without cr ...