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

Is your margin not functioning correctly? Is padding taking on the role of margin?

One issue I'm encountering is that the margin isn't behaving as expected in this example. The padding seems to be working like margin should. Why is that? Print Screen: https://i.stack.imgur.com/N1ojF.png Why is it that the margin in the h3 ta ...

The grid columns are not utilizing the entire space of the rows and are extending beyond to the next line

I'm currently designing a card layout with images and aiming for uniformity in size. The plan is to have 4 columns in each row, with one card per column. Each subsequent row will also contain 4 cards. However, there seems to be an issue where the ca ...

Employing bootstrap to include oversized images within a compact, fixed div

I am facing an issue with image responsiveness in the middle row of my layout. Despite using Bootstrap 4 and applying classes like img-fluid, the images in my #fullColumn area do not resize properly. The images are dragged into this area by users and are ...

Is there a way to assign a specific color to individual users in a chat?

I have successfully implemented a chat feature using Pusher, but now I want to customize the appearance by changing the color of the username for the logged-in user when they are active in the conversation. Currently, both my username and another user&apos ...

Applying a gradient overlay to an image using CSS

Feeling a bit frustrated with this issue. I'm working on my Joomla website utilizing Phoca Gallery, and the code it generates includes the following: <img class="pg-image" src="/images/phocagallery/other/thumbs/phoca_thumb_m_something.jpg" alt="So ...

Using CSS absolute/relative positioning in a flyout menu: Utilizing specific parent properties (such as left, top, width, vertical/horizontal alignment) while disregarding others

I recently encountered a common issue in CSS involving flyout menus with sub-menus that are shown on hover. When attempting to position the sub-menu directly below the parent list item, I used position:relative; on the parent item and position:absolute;top ...

How can you fix a navbar that won't stay in place?

I'm facing an issue with this example: When I scroll, the navbar moves along due to the fixed property, which affects the overall look. How can I make it disappear when scrolling, while keeping the logo intact? Can someone suggest if this layout is ...

Having trouble establishing a connection to a redis client through my nuxt 3 middleware as the connection keeps returning as undefined

I have been struggling to establish a connection to a Redis server in order to retrieve my session data from a Nuxt 3 defineNuxtRouteMiddleware middleware. Although I successfully create the connection to Redis in a server-side plugin and it functions prop ...

Various results can be produced based on the .load() and .resize() or .scroll() functions despite using the same calculation methods

I'm currently working on developing my own custom lightbox script, but I've hit a roadblock. For centering the wrapper div, I've utilized position: absolute and specified top / left positions by performing calculations... top: _center_ver ...

If the option is 'Gel', use an if statement to console log

I'm trying to console.log the option from the data() function that is equal to 'Gel'. I attempted to use an if statement, but it doesn't seem to be working. Anyone have any ideas on how to make this work? data(){ return { ...

Choose the radio button upon clicking away from the input field

Currently, I have a standard Bootstrap 4 accordion that contains a radio button. Here is the code snippet: <div class="card"> <div class="card-header" id="headingOne"> <h2 class="mb-0"> ...

Tips for improving the styling of a django form with mixed elements

Here are two different forms I am working with: class InitialForm(Form): trn = IntegerField(widget=NumberInput, required = False) klient = ChoiceField(choices=KLIENTS, required = False) class SecondForm(Form): faktura = CharField(max_length = ...

AngularJS | Using ngAnimate to Display Form Validation Errors

My form errors are currently being displayed successfully using CSS and conditional classes, but I recently discovered ng-message and ng-animate. Would it be possible to use ng-message to contain the error messages? Also, I have been unable to find any tu ...

What distinguishes line-height:1.5 from line-height:150% in CSS?

Does anyone have any information on this? ...

Modifying jQuery CSS causes certain CSS rules from a file to be deleted

When using jQuery to change the css of an element, I've noticed that it can remove some previously specified css rules for that element. For example, .className, .className2, etc... { background-color: black; color : silver; } .className: ...

How can I code a div to automatically scroll to the top of the page?

I'm attempting to implement something similar in WordPress - I want a div containing an advertisement to initially start 300px down the page, then scroll up with the page until it reaches the top, and finally stay there if the user continues to scroll ...

Tips on effectively centering a wide div

After much experimentation, this is what I came up with: (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en ...

Using Vue Js directive to implement a Select2 component

I've been exploring the example of the Vue.js wrapper component and trying to customize it to use a v-select2 directive on a standard select box, rather than creating templates or components for each one. You can view my implementation in this JS Bin ...

Wordpress is having issues running jQuery

I've developed a function inside js/custom.js. The purpose of this function is to arrange posts in my Wordpress site by applying a class called articleAlign. This class will enhance the spacing between the article title and its excerpt, but only when ...

Ensure alignment of gradients between two divs, even if their widths vary

Among my collection of 10 inline divs, each one boasts a unique width and color gradient. While the 45-degree lines are uniform across all the divs, is there a way to ensure that these gradients match seamlessly? I've shared my CSS code snippet below ...