vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

overwriting font-family

Open noorzaie opened this issue 7 years ago • 57 comments

There are many inline font-families and so it's not possible to overwrite them using sass variables.

image

noorzaie avatar Jul 30 '19 06:07 noorzaie

Please only create issues with the provided issue creator. In the boilerplate for creating an issue, it explains that any ticket made without this will be automatically closed. For general questions, please join the Discord chat room. You can also check reddit or stackoverflow. Thank you.

close-issue-app[bot] avatar Jul 30 '19 06:07 close-issue-app[bot]

@noorzaie Probably better to ask this in the discord channel. Anyway, here's how you change the font:

Add custom sass file as per the instructions in the docs: https://vuetifyjs.com/en/customization/sass-variables

Then add this in your sass file

@import "~vuetify/src/styles/styles.sass";
@import url("https://fonts.googleapis.com/css?family=Maven+Pro:400,500,700,900&display=swap");
$body-font-family: "Maven Pro" !important;

And replace the font with whatever font you want.

thomas-kuhlmann avatar Jul 30 '19 13:07 thomas-kuhlmann

This just changes global font family. But the problem I've faced is inline styles. You can see inline font-family in image I've attached. So overwriting $body-font-family won't work in this case. The value of $body-font-family is "Roboto", sans-serif !default and is different from inline styles, So I think inline font-families are not using from the sass variable.

noorzaie avatar Jul 30 '19 14:07 noorzaie

https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/styles/elements/_typography.sass#L42

jacekkarczmarczyk avatar Jul 30 '19 14:07 jacekkarczmarczyk

Reopened this because I got the same issue, the font doesn't apply to headings (h1, h2...) tags... So when using typography with class like title (which is h6) the custom font doesn't get applied... A comment in SO also stated it: https://stackoverflow.com/questions/45598884/change-default-font-in-vuetify

filipyoo avatar Aug 04 '19 09:08 filipyoo

I had to declare my custom font-family before importing the default vuetify style in my custom main.scss. That way vuetify properly picks up the custom definition:

$body-font-family: ...;

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

andrewsali avatar Aug 04 '19 11:08 andrewsali

Thank you for your reply! Unfortunately it still doesn't work for me... I did the way you described, and in my nuxt.config.js I have:

  head: {
    ...
    link: [
      {
        rel: 'stylesheet',
        href: 'https://fonts.googleapis.com/css?family=Varela+Round'
      }
    ]
  },
  /*
   ** Global CSS
   */
  css: ['~/assets/scss/main.scss'],
  ...
  modules: [
    '@nuxtjs/style-resources',
  ],
  styleResources: {
    scss: ['~/assets/scss/variables.scss']
  },
  ...
  vuetify: {
    customVariables: ['~/assets/scss/variables.scss'],
    theme: {
    ...
      }
    }
  },

And in my ~/assets/scss/main.scss file:

$body-font-family: 'Varela Round';
$heading-font-family: 'Varela Round'; // With or without this line, it still doesn't work

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

filipyoo avatar Aug 04 '19 16:08 filipyoo

None of the solutions work: I have nuxt.config with

 buildModules: [
    // https://github.com/nuxt-community/vuetify-module#readme
    '@nuxtjs/vuetify'
 ...
]
...
vuetify: {
customVariables: ['~/assets/scss/vuetifyvariables.scss'],
 theme: {
   dark: false
}
....

and in my ~/assets/scss/vuetifyvariables.scss I wrote:

 $body-font-family: 'FSAlbertWeb-Regular',Helvetica,sans-serif;
 @import "~vuetify/src/styles/styles.sass";

Still I see:

.v-application {
    font-family: "Roboto", sans-serif;
    line-height: 1.5;
}

pimboden avatar Nov 08 '19 10:11 pimboden

Has anyone solved this problem?

leasontou avatar Dec 13 '19 07:12 leasontou

No.. They "solved" it by closing the issue without a solution. I had to overwrite it by css using important!

pimboden avatar Dec 13 '19 07:12 pimboden

No.. They "solved" it by closing the issue without a solution. I had to overwrite it by css using important!

emmm... I think I will follow your steps.

leasontou avatar Dec 13 '19 07:12 leasontou

I had to declare my custom font-family before importing the default vuetify style in my custom main.scss. That way vuetify properly picks up the custom definition:

$body-font-family: ...;

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

In case anyone else is reading this, this definitely worked for me.

JosephSaw avatar Dec 25 '19 06:12 JosephSaw

I also cant change the font family. I have this:

@import './fontface.scss';

$body-font-family: 'GT-Walsheim-Regular', sans-serif;
$heading-font-family: 'GT-Walsheim-Regular', sans-serif;

@import '~vuetify/src/styles/settings/_variables';

@each $heading, $style in $headings {
    $headings: map-merge($headings, ($heading: map-merge($style, ('font-family': $heading-font-family))));
}

Anyone can help?

pwnz22 avatar Dec 25 '19 12:12 pwnz22

Is there any working example of how to replace main fonts?

alvaro-canepa avatar Jan 03 '20 08:01 alvaro-canepa

Worked for me!

nuxt.config.js

vuetify: {
  customVariables: ['~/assets/variables.scss'],
  theme: {
    dark: false
  }
},

variables.scss

$body-font-family: Montserrat;

.v-application {
  .display-1,
  .display-2,
  .display-3,
  .display-4,
  .headline,
  .title,
  .subtitle-1,
  .subtitle-2,
  .body-1,
  .body-2,
  .caption,
  .overline {
    font-family: $body-font-family !important;
  }
}

imperatormk avatar Jan 10 '20 19:01 imperatormk

@filipyoo, @pimboden: Perhaps you are missing treeShake: true in nuxt.config.js file vuetify section?

I wrote a short article explaining the solution, there's also a complete code example at the end: https://medium.com/untitled-factory/changing-default-font-in-vuetify-js-and-nuxt-js-3894e726ff10

loomchild avatar Feb 10 '20 12:02 loomchild

Re-open this, it's not fixed. It's literally impossible to override the default Roboto font.

indigoswann avatar Feb 14 '20 13:02 indigoswann

Same here, trying everthing. Nothing work.

joaokrabbe avatar Feb 17 '20 19:02 joaokrabbe

I find a workaround!

I tried to use custom variables, but the import import 'vuetify/dist/vuetify.min.css'; was overwriting my definitions. So I appealed to css specificity, and setup my overwriting with css id, and it's beats the class overwrite from vuetify.min.css.

If anyone needs, just create this file on ./src/sass/variables.scss:

// @/sass/variables.scss

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700,800&display=swap');

$body-font-family: 'Open Sans';

$typoOptions: display-4, display-3, display-2, display-1, headline, title, subtitle-1, subtitle-2, body-1, body-2, caption, overline;
#app {
  font-family: $body-font-family, sans-serif !important;
  @each $typoOption in $typoOptions {
    .#{$typoOption} {
      font-family: $body-font-family, sans-serif !important;
    }
  }
}

P.S.:

  • I know that I no need custom variables to do that, but since that is already loading by vuetify-loader, seems comfortable to use that way until another solution appears.
  • I have installed vuetify using vue cli 3, so the vuetify-loader will automatically bootstrap the file, already said that, rsrs.
  • typoOptions is the classes that you want to replace, and if you set in #app like me, this will replace everything too.
  • #app is the id from div used to mount Vue

So i forced this by css, is not ideal but... it that I have for now. I Hope this help anyone else.

joaokrabbe avatar Feb 22 '20 23:02 joaokrabbe

Salvation is easy peasy, do not use this crap. if you need something, take a look and reverse engineer it.

BonBonSlick avatar Feb 23 '20 06:02 BonBonSlick