Change headers default font on Vuetify - vue.js

I've just upgraded to Vuetify 2.0 and my fonts are totally broken.
I've managed to change the font on the project by:
.v-application {
font-family: 'Montserrat', sans-serif!important;
}
But the headings that have applied classes like .display-1, .display-2 are still taking the Vuetify default (Roboto) because it has an !important in the Vuetify default styles.
How could I change the font for the entire project, overriding Vuetify's default?

You can change the default font for a specific type of typography like h1 and h2 and specifically the font-family property in the following manner in a global css file for example:
$headings: (
'h1': (
'font-family': 'Calibri',
'size': 60px,
'line-height': 60px,
'weight': 400
),
'h2': (
'font': 'Ariel',
'size': 48px,
'line-height': 48px,
'weight': 400
),
)
And than you can give these utility classes in the Vuetify way like so class="text-h1" or class="text-h2"
You could do the same in Vuetify to override the following built in(and exposed via API for modifications) utility classes:
h3
h4
h5
h6
body-1
body-2
subtitle-1
subtitle-2
button
caption
overline
If you need any further utility classes, for example that are derived from your internal design system you can add them in that global scss/css file and I recommend doing so while keeping the Vuetify naming convention.
For example if you need a body-3 or subtitle-3 you could add them like so
.text-body-3 {
// your custom style
}
.text-subtitle-3 {
// your custom style
}

In Vuetify 2.x you can customize scss variables in your variables.scss file. You probably need to set the $body-font-family and $heading-font-family variables.
There are a lot of variables documented here and many changed around Vuetify 2.3.
An example:
$font-size-root: 18px;
$body-font-family: 'Roboto', sans-serif;
$heading-font-family: 'Libre Caslon Text', serif;
$btn-text-transform: none;
Additional information for overriding specific styles:
You can further override individual styles such as text-h1 by adding a $headings to the same file.
$headings: (
'h1': (
'size': 4.0rem,
'weight': 400,
'line-height': 4.444rem,
'letter-spacing': 1em,
'text-transform': false
)
)
The valid values you can customize are listed on the typography doc. Those currently include:
h1
h2
h3
h4
h5
h6
subtitle-1
subtitle-2
body-1
body-2
button
caption
overline
These all generate text-X classes. ex: text-body-2
Also its important to note that even if you override these styles it will not change the type settings for elements of the same name (like h1). Instead you need to apply that style with class="text-h1". This is easy to miss in the docs.
Right:
<h1 class="text-h1">my header</h1>
Wrong:
<h1>my header</h1>
Also if you're not yet on 2.3 the names are different. If you follow github issues there have been a lot of changes around typography leading to this current system.

Related

How to change font-family in Vuetify?

The default Vuetify font family is Roboto and I would like to change this. I found other solutions that changes the font family globally. I don't want to change it globally, I only want to change it for a specific element. How to do this?
<template>
<v-container>
<div class="text-h4">Text family I want to change</div>
<div class="text-h6">Text family I dont want to change/give another font family</div>
</v-container>
</template>
Update
Vuetify declares the font on .v-application and unfortunately also declare the font as !important on .v-application .text-hN. I can suggest you some ideas to modify your font:
If you want to change every text-h4: You can override the style of text-h4 by modifying its default ($headings then
'h4') https://vuetifyjs.com/en/features/sass-variables/#example-variable-file
If you want to keep default text-h4: You can remove the text-h4 class and use your own class custom-header with copied rules of text-h4 plus your font-family rule. You won't need higher specificity, nor to use !important.
Something like:
.custom-header {
font-size: 2.125rem !important; /* from .text-h4 */
line-height: 2.5rem; /* from .text-h4 */
letter-spacing: .0073529412em !important; /* from .text-h4 */
font-weight: 400; /* from .text-h4 */
font-family: YOUR_FONT_FAMILY, Roboto, sans-serif;
}
Previous answer
Give your element another class:
<div class="text-h4 anotherClassForExample">Text family I want to change</div>
Override the font-family of this new class in your css.
I was in a similar position before, I had some basic css knowledge and started using frameworks. I strongly recommend you to master CSS before using a UI framework. Starting by using a framework looks faster, shinier and easier but in the long term it is not. You will be blocked a lot and maybe in the future you will change to another one or even want to not use any.

How can I change the font for all items in Vuetify from Roboto to another

How can I change the font for all items in Vuetify from Roboto to another.
I use Vuetify, there is a default Roboto font. I want to change it to another. Changing the font in the variables.scss file does not help, because each class has a specific Roboto font.
#import url('https://fonts.googleapis.com/css? family=Oxygen:300,400,700&display=swap');
#import url('https://fonts.googleapis.com/css? family=Comfortaa&display=swap');
$body-font-family: 'Oxygen';
$title-font: 'Comfortaa';
$heading-font-family: 'Oxygen';
However, when I use classes like this:
class = "text-md-h6 text-lg-h6 .text-xl-caption"
the Roboto font is still used.
#media (min-width: 1024px)
<style>
.v-application .text-xl-caption {
font-size: 0.75rem !important;
font-weight: 400;
line-height: 1.25rem;
letter-spacing: 0.0333333333em !important;
font-family: "Roboto", sans-serif !important;
}
What do I need to do to change the font in all places?
This should work by setting the font variables in variables.scss file as documented here. A couple things to check if it doesn't work:
The file should be in an expected folder src/[sass, scss or styles]. Docs.
Vuetify Loader should be installed along with sass and sass-loader as dev dependencies
Variables file only contains variables, not imports. Fonts could be declared/imported in main or elsewhere.
it's a bad practice to use !important for most of the cases and unfortunately because those font-family styles also have !important CSS will only use the style with a more specific selector so You also have to use !important. You can try something like .v-application .v-application--wrap * with !important. so it will be like :
.v-application .v-application--wrap * {
font-family: $body-font-family !important;
}
and if you have different styles for different classes , you can just put all of them inside a .v-application .v-application--wrap { } and sass will process them for you. but also note that other vuetify classes might use more specific selectors , so in those cases you have to use more specific selectors for those specific cases.

How to customize the backgorund-color of cancel-button in b-modal?

I need to change the background-colour of the cancel-button with rgb. The only half-way up to now is changing the cancel-variant to e.g danger. However, I need to choose the specific, rgb colour. Does anyone know a solution to my problem?
Thank you
<b-modal v-bind:id="'delete-modal-' + id" cancel-variant=info ok-variant=danger ok-title="delete" cancel-title="back" #ok="deleteModal" title="Caution">
<p class="my-4">Are you sure?</p>
</b-modal>
If you're using SASS you can easily add new variants to your project by adding them to the $theme-colors map.
These will automatically become available to use with bootstrap-vue everywhere you can use a variant.
custom.scss
$theme-colors: (
"cancel": rgb(139, 80, 80)
);
#import 'node_modules/bootstrap/scss/bootstrap';
#import 'node_modules/bootstrap-vue/src/index.scss';
Then import custom.scss in your apps entry point.
If you want a simple CSS solution, the cancel-variant property just adds the class btn-* where * is the string you provide.
Which means you can add the css below to your global stylesheet, to add a new variant (however, doing it this way you'll have to write all the :hover, :active stuff yourself)
.btn-cancel {
color: #fff;
background-color: rgb(213, 213, 213);
border-color: rgb(213, 213, 213);
}
After adding one of the options above you will now have the option to do <b-modal cancel-variant="cancel"></b-modal> to utilize your new variant.

linear-gradient in scss with dynamic percentages

I want to make a progress bar with background linear-gradient and use pre-defined theme colors in scss in vue. Such as:
.progress{
background-image: linear-gradient(to right, $start-color 0%, $start-color 50%, $end-color 50%, $end-color 100%);
}
50% is dynamic changed by code in vue. If I write the style in :style="{}" then I can't use the pre-defined scss color $start-color and $end-color
You should use the :export block from Interoperable CSS under CSS modules.
As an example consider the below given extracts, first in your sass file that has colors defined (say colors.scss):
$primaryColor: #fcf5ed;
$secondaryColor: #402f2b;
:export {
primaryColor: $primaryColor;
darkColor: $secondaryColor;
}
With that setup along with your style loaders (which you currently must have setup) you can just import the file like usual js modules like below in your Vue application:
import colorVariables from 'colors.scss'
colorVariables.primaryColor // => Will now have the value of the color as a string.
Now you can just use the :style binding of the Vue to define the linear-gradient. You can read more on export in the following link : Interoperable CSS - :export under CSS modules.

Dojo - Tree in accordion is broken (while outside is ok) , Why?

I've made simple application with dojo.
I took the exact same combo tree (cbtree) and put it once inside accordion and once first on page.
I don't understand why inside the accordion I get different cbTree (it looks really bad)
Here is online example of the problem :
http://77.235.53.170/cbTree/cbTree.htm
The problem is at your main.css, you have
#leftCol img {
width: 100%;
}
Which overwrites
.dijitFolderOpened, .dijitIconFolderOpen, .dijitIconError {
background-image: url("../../icons/images/commonIconsObjActEnabled.png");
width: 16px;
height: 16px;
}
You need resolve this in main.css by either removing your style, or changing it to a more specific rule; i.e. instead of #leftCol img, use #leftCol .yourClass.