I am attempting to use a custom font using #font-face to my CSS file in Visual Studio. Note I am brand new to web development.
In Visual Studio, functions are color coded, and the url() part of my code below is not colored in like I see in other posts on StackOverflow and in YouTube tutorials.
The .ttf file is located in the same folder as my CSS file.
I am wondering if there is something I need to install to get the url() function to call properly.
#font-face {
font-family: 'example_font';
src: url(example.ttf) format(truetype);
}
body {
font-family: 'example_font', 'Arial';
text-align: center;
background-color: wheat;
}
I have tried moving the ttf file and updating the path location as well as opening my html file in separate browsers. I have also edited the backup font 'Arial' to other fonts and have found they changed the font in my browser when calling my HTML file. \
[image of the lack of url() coloring] (https://i.stack.imgur.com/QxVTJ.png)
I'm using the open-iconic library that comes with the default Blazor template in Visual Studio.
It's referenced in the css file #import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
I added some custom ttf fonts to my root folder. When referencing them in the css file like this:
#font-face {
font-family: ALittlePot;
src: url('../fonts/ALittlePot.ttf') format('truetype');
}
then the open-iconic icons disappear. I even tried removing the content and just putting #font-face { } the same thing happened. It obviously has something to do with using #font-Face.
I tried adding my font using #import url('../fonts/ALittlePot.ttf'); but then the font didn't render.
Where am I going wrong?
I have a .otf font file that I am trying to use in my ASP.NET Core project.
In the wwwroot folder, I have created another folder named font where the .otf file resides.
In my css file I have the following:
##font-face {
font-family: 'Nexa Light';
src: local('../font/Nexa Light.otf'), url('../font/Nexa Light.otf');
}
body {
font-family: 'Nexa Light';
}
The font has not been applied and there are no errors in Chrome Dev console so.
Any help is much appreciated.
I have created another folder named fonts where the .otf file resides
In your code you have written font in the path : src: local('../font/Nexa Light.otf'), url('../font/Nexa Light.otf');
Check that font folder name
Avoid using blank spaces (whitespace) in font names, use instead "_" or "-" to avoid blank spaces (whitespace).
These can be cause above issue.
Try using below code :
#font-face {
font-family: myFirstFont;
src: url(fontname.woff);
}
i want to change semantic-ui default font with #font-face but no matter...
i tried change in less file(site.variables) but I do not know how change it
i tried add my font with other custom css file but it not work
#font-face {
font-family: 'fontname';
src:url('themes/basic/assets/fonts/fontname.eot');
src:url('themes/basic/assets/fonts/fontname.eot?#') format('eot'),
url('themes/basic/assets/fonts/fontname.woff') format('woff');
}
body{
font-family: 'fontname';
}
I know two ways to change font-face, using google fonts or offline fonts:
Using google fonts:
We need to have the resources of Semantic UI, you can get here:
https://semantic-ui.com/introduction/getting-started.html
It is required to create the file site.variables in semantic/src/site/globals/
We search for the source that we like most at https://fonts.google.com/ and copy the name.
In the file site.variables we add the name of the font to the variable #fontName as follows:
/*******************************
User Global Variables
*******************************/
#fontName : 'Roboto';
Finally we execute the command glup build-css, the changes will be reflected in the file semantic /dist/semantic.css
Using offline fonts
We need to have the resources of Semantic UI, you can get here:
https://semantic-ui.com/introduction/getting-started.html
It is required to create the file site.variables in semantic/src/site/globals/
In the file site.variables we add the variable #importGoogleFonts with the value false;
/*******************************
User Global Variables
*******************************/
#importGoogleFonts : false;
#fontName : 'fontname';
It is required to create the file site.overrides in semantic/src/site/globals /
In the file site.overrides we add our font-face
/*******************************
Site Overrides
*******************************/
#font-face {
font-family: 'fontname';
src:url('themes/basic/assets/fonts/fontname.eot');
src:url('themes/basic/assets/fonts/fontname.eot?#') format('eot'),
url('themes/basic/assets/fonts/fontname.woff') format('woff');
}
Finally we execute the command gulp build-css, the changes will be reflected in the file semantic /dist/semantic.css
This video maked by #Aditya Giri explain how change font family from google fonts
https://www.youtube.com/watch?v=cSdKA-tZEbg
In the next issue #jlukic explain how use offline fonts
https://github.com/Semantic-Org/Semantic-UI/issues/1521
Regards
You can do the following:
Add the following to a .css file:
#font-face {
font-family: 'fontname';
src:url('themes/basic/assets/fonts/fontname.eot');
src:url('themes/basic/assets/fonts/fontname.eot?#') format('eot'),
url('themes/basic/assets/fonts/fontname.woff') format('woff');
}
Import the above code before semantic's site.min.css
Change the #fontName to 'fontname'
#importGoogleFonts should be false since you don't want to import any fonts from Google
By default the above will applied to body
It's an old question but I just wanted to add one thing.
Because all Semantic UI elements inherits the ui class you could do it like this:
.ui {
font-family: 'fontname' !important;
}
Not so elegant but it works.
This is the complicated solution https://stackoverflow.com/a/54208399/2374997 but if you want a simpler approach you could follow this example:
/*In your .css file, loaded after semantic.min.css*/
#import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap');
* {
font-family: 'Montserrat' !important;
}
You can use google Link:
Add to index.html google link. For example:
<linkhref="https://fonts.googleapis.com/css2?family=Rubik+Glitch&display=swap"rel="stylesheet"/>
Add Font in semantic.ui> site> globals > site.variables. For example:
/*******************************
User Global Variables
*******************************/
/*--FONTS--*/
#pageFont: Rubik Glitch;
Don't know how to load ttf font types on css files for twig in symfony2 app. Any suggestions? The ttf are inside a folder in resources. Thanks
Load font in twig? You probably want to have some custom fonts in you CSS file that defines styling of the twig.
#font-face {
font-family: GiveItSomeName;
src: url(locationToYourFont.ttf);
// you can add stuff like font-style, or font-weight...
}
And then later in your CSS file, use it like there was a font named GiveItSomeName in those classes you wish, like this
.someClass {
font-family: GiveItSomeName;
}