vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Feature Request] About changing default font of Vuetify

Open kingdom84521 opened this issue 7 years ago • 16 comments

Problem to solve

When using chinese in vuetify's tags, the default font: roboto, just can't properly suit to those chinese words, and would automatically change the font into a chinese font called "PMingLiU", which is the chrome browser's default font for chinese words. There are several ways to change default font which was found by some hackers online, but seems like there isn't a official way to change it.

Proposed solution

I have looked into the css code, and found that there is a "!important" at the place where defined the default font, which was cannot be override. Just looking for a method to override this part of code.

kingdom84521 avatar Oct 11 '19 11:10 kingdom84521

You can add a class to v-app and apply font-family. https://codepen.io/dev0x0/pen/eYYJgQK

melbahja avatar Oct 12 '19 11:10 melbahja

already add things like

  • { font-family: "Font Name" }

but it didn't actually work because of "!important"

kingdom84521 avatar Oct 13 '19 08:10 kingdom84521

OK, i found that the problem is actually came from vuetify's typography. When using typography classes, the font-family will be lock at roboto and can't change to another. i know that i can just add a css class to define a customize typography like the comment say above, but i still want to know if there is a way to change the default font family( and also i am not really sure if the "!important" keyword only works on typography classes. )

kingdom84521 avatar Oct 13 '19 09:10 kingdom84521

Just found a way to use sass file to override the "body-font-family" variable, but still wondering if there can have a easier official method.


( Using vue-cli 3 )

  1. Create a .sass file in your project folder, write down these code into the file:
@import '~vuetify/src/styles/styles.sass'
// If you need to import the font family from CDN then add a import line

$body-font-family: "YOUR FONT FAMILY NAME"
​
$typoOptions: display-4 display-3 display-2 display-1 headline title subtitle-1 subtitle-2 body-1 body-2 caption overline
​
%font-choice 
  font-family: $body-font-family, sans-serif !important
​
@mixin md-typography
  @each $typoOption in $typoOptions 
    .#{$typoOption} 
      @extend %font-choice
​
.v-application
  @extend %font-choice
  @include md-typography
  1. Add a line at vuetify.js which locate at src/plugins like below:
    import Vuetify from 'vuetify/lib'
    import 'YOUR_SASS_FILE_PATH' // Add this line
    // You can use "@" to shorten the path, which represent the "src" folder.
  1. Run the project then you will see the difference.

kingdom84521 avatar Oct 13 '19 16:10 kingdom84521

There are instructions on how to do this on the documentation. https://vuetifyjs.com/customization/sass-variables

johnleider avatar Oct 17 '19 16:10 johnleider

that didn't work at all, already try it before

kingdom84521 avatar Oct 18 '19 13:10 kingdom84521

I replaced with Google Font "Poppins" like below;

  1. Replace font in index.html
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:100,300,400,500,700,900">
  1. Set font-family in App.vue
<style lang="scss" scoped>
  .v-application {
    font-family: 'Poppins', sans-serif;
  }
</style>

@johnleider Is my solution okay?

diamond122 avatar Nov 13 '19 12:11 diamond122

@Antonio-Collins regrettably your solution didn't work.

I added to the head tag of the index.html:

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i&display=swap">

and to the App.vue:

<style lang="scss" scope>
  @import "./scss/_variables.scss"; 
  .v-application {
    font-family: 'Lato', sans-serif;
  }
  .font-white {
    color: $white;
  }
</style>

Zero luck. :(

acarlstein avatar Jan 09 '20 17:01 acarlstein

@acarlstein It was working on my side.. Could you please share the template in App.vue?

diamond122 avatar Jan 10 '20 06:01 diamond122

I have done something that doesn't need so much configuration like installing a ton of package. if you dont have a global css, just make one then type this

  • { font-family: "selawk", sans-serif !important; }

jarvilito1234 avatar Jun 03 '20 07:06 jarvilito1234

UPDATE Jan/04/2020 https://vuetifyjs.com/en/customization/sass-variables/#example-variable-file

// src/sass/variables.scss

// Globals
$body-font-family: 'Work Sans', serif;

diamond122 avatar Jun 03 '20 12:06 diamond122

UPDATE Jan/04/2020 https://vuetifyjs.com/en/customization/sass-variables/#example-variable-file

// src/sass/variables.scss

// Globals
$body-font-family: 'Work Sans', serif;

This do not work.... about 2 hours trying to make it work using the same tutorial

AllanPinheiroDeLima avatar Nov 28 '20 05:11 AllanPinheiroDeLima

Not the best but I managed to simply overwrite it by placing this on the highest level parent component ( in my case default.vue since im using nuxt.js

.v-application {
	font-family: 'Poppins', 'Open Sans', 'Helvetica Neue', sans-serif !important;
}

Dorianslavov avatar Dec 26 '20 23:12 Dorianslavov

UPDATE Jan/04/2020 https://vuetifyjs.com/en/customization/sass-variables/#example-variable-file

// src/sass/variables.scss

// Globals
$body-font-family: 'Work Sans', serif;

Working for me.

People for whom it did not work, please make sure you have variables.scss or variables.sass in src/sass directory.

FULL PATH: src/sass/variables.scss

Vuetify will automatically look for the sass folder. You just have to create sass folder with variable file in it.

vishalarpitkumar avatar Jan 17 '21 07:01 vishalarpitkumar

UPDATE Jan/04/2020 https://vuetifyjs.com/en/customization/sass-variables/#example-variable-file

// src/sass/variables.scss

// Globals
$body-font-family: 'Work Sans', serif;

This do not work.... about 2 hours trying to make it work using the same tutorial

This work for me, check your folder name. If your variables file has extension .scss then your folder must be named scss or styles (I prefeer styles). If the folder and file name are correct, then this file is load by vuetify bootstrap loader automatically. If you create the new folder is very important stop the server and re run!

FenoRC avatar Feb 21 '21 16:02 FenoRC

We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression.

If you have any additional questions, please reach out to us in our Discord community.

johnleider avatar Feb 22 '21 18:02 johnleider