How to change font-family in Vuetify? - vue.js

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.

Related

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 set light and dark modes with SCSS variables

I want to make a light mode for a website that uses SASS with variables in it. So, here are the variables and smth I tried (but doesn't work):
#media (prefers-color-scheme: dark), (prefers-color-scheme: no-preference) {
$bg: #0d0d0e;
$c0: #ffffff;
$c1: invert(#333);
$c2: #7c7c7c;
$c3: invert(#aaa);
$c4: invert(#eee);
}
#media (prefers-color-scheme: light) {
$bg: #fff;
$c0: #000;
$c1: #505050;
$c2: #66666a;
$c3: #aaa;
$c4: #eee;
}
I have to keep SCSS. Should I try #mixin?
That won't work with Sass variables during runtime since they are being compiled and then statically served. What you can do though is using CSS custom properties aka CSS variables. Those can be changed during runtime with Javascript (more versatile) or use media queries along with the boolean context value prefers-color-scheme. This value is unfortunately set by the user's browser environment and cannot be changed with Javascript.
You can however just switch the colors around with Javascript. With an onClick event you just save the state of current color in a buffer, assign the current color with the alternative color and then set the alternative color to the one saved in the buffer (aka the former current color).
I've tried switching around colors stored in CSS custom properties with a checkbox and the input:checked selector but the changes have only local scoping (thanks, W3C), so they won't do you any good - that is of course unless you want to wrap your whole website in your color switcher element.
The only way with Sass variables would be to recompile the Sass stylesheets when a user switches over the color scheme.
tl;dr: use CSS custom properties and either go with browser defaults in media queries or use a bit of Javascript. Everything else is very hacky.
I'm defining each theme side by side and using them inside #media (prefers-color-scheme).
Even made my self a mixin:
/** Helper to tigth properties to color preferences */
#mixin color-scheme($value: light) {
#media (prefers-color-scheme: $value) {
#content;
}
}
/** Usage */
.element {
/* ... */
#include color-scheme(dark) {
/* ... */
}
}

Buefy b-table headers not recognizing CSS styles

I am trying to change the background-color of my b-table headers, but the style is not being recognized.
<style scoped>
.b-table .table th {
background-color: #f3dcba !important;
}
</style>
Does anyone have any suggestions on possibility of fault?
I was going through the same issue, and the problem here is that you are trying to overwrite the style of a component that is not in the same scope as your Vue file.
One thing you can do, is to remove the scoped directive, and that would allow you to overwrite the style like so:
<style>
.b-table th { ... }
</style>
Be mindful that this might not be the best approach for this situation, and perhaps you should be creating a new slot for the table-headers, by creating some Custom Headers. Once you've done this, you should be able to insert some specific class for the table-header in question, and even insert other custom behaviours.

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.

Use Font Awesome (5) icon in input placeholder text

I've come across many ways to solve this using Font Awesome < 5, but I can't seem to solve this in any way using Font Awesome 5.
This is how many resources point to adding a Font Awesome icon in placeholder text.
<input style="font-family:FontAwesome !important" type="text" placeholder="&#xf167">
Remember to not use the general "Font Awesome 5" font family, you need to specifically end with the branch of icons you're working with. Here i am working the "Brands" category.
<input style="font-family:'Font Awesome 5 Brands' !important" type="text" placeholder="&#xf167">
For a more sophisticated solution you could implement a class that works specifically on the placeholder text of a class like this and add that class to you input. Useful if you want a different font-family on your input values.
.useFontAwesomeFamily::-webkit-input-placeholder { /* WebKit, Blink, Edge */
font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::-moz-placeholder { /* Mozilla Firefox 19+ */
font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily:-ms-input-placeholder { /* Internet Explorer 10-11 */
font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::-ms-input-placeholder { /* Microsoft Edge */
font-family: "Font Awesome 5 Brands" !important;
}
.useFontAwesomeFamily::placeholder { /* Most modern browsers */
font-family: "Font Awesome 5 Brands" !important;
}
And then add this class to your tag.
<input class="useFontAwesomeFamily" type="text" placeholder="">
This might help someone out there as I had the same issue.
The Branch for Regular icons is Font Awesome 5 Free. However, if you need to use solid icons, just add the font-weight: 900; property to the inline CSS.
<style="font-family: Circular, 'Font Awesome 5 Free' !important; font-weight: 900;">
The placeholder text will be bold, I'm still trying to find a solution for this, I don't know if there's another way but it works for me for now.
I hope it helps.
You can also the fas class to the input.
Just bear in mind that this solution and any font-awesome style changing solutions will also change the style of any text preceding or following the unicode icon.
Remember to add class "fas fa-search" to the input