Can't load specific Roboto font - css

My problem is very simple and the symptom is weird.
In the head of my HTML, I have included the code to load the font directly from Google Font.
<link href="https://fonts.googleapis.com/css?family=Roboto:700" rel="stylesheet">
And this is my CSS:
.text {
font-family: 'Roboto', sans-serif;
color: white;
font-size: large;
}
No matter what customization I choose, the font seems to be the normal font. I tried with Roboto Thin (Roboto:100) and Roboto Thin Italic (Roboto:100i) but none of them actually change.
Is there anything that I miss in my code?

It depends on which font you have from google, in this case:
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
You approach to each font weight in CSS like that:
// 300 weight
.text {
font-family: 'Roboto', sans-serif;
font-weight: 300;
}
// 400 weight
.text {
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
// 700 weight
.text {
font-family: 'Roboto', sans-serif;
font-weight: 700;
}

You are loading Roboto font with 700 font weight and trying to show it with 100 font weight. Embed it with the following URL:
<link href="https://fonts.googleapis.com/css?family=Roboto:100,100i,400,700" rel="stylesheet">
Using this link, it will work fine for you.
Update: This code snippet will explain you it in detail.
.text {
font-family: 'Roboto', sans-serif;
color: #000;
}
.text-100 {
font-weight: 100;
}
.text-100i {
font-weight: 100;
font-style: italic;
}
.text-400 {
font-weight: 400;
}
.text-700 {
font-weight: 700;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,100i,400,700" rel="stylesheet">
<div class="text text-100">
Hello (Font weight: 100)
</div>
<div class="text text-100i">
Hello (Font weight: 100i)
</div>
<div class="text text-400">
Hello (Font weight: 400)
</div>
<div class="text text-700">
Hello (Font weight: 700)
</div>

You simply need to set the font of your weight in your CSS
.text {
font-weight: 700;
}

First of all load all the fonts-
Just use
font-weight: 100|300|700 /Any one of them/ .
Google fonts basically work with font-weight property. The google fonts are rendered according to the font weight specifications.
For example-
Case 1 - font-weight:100 then thin font will load.
Case 2 - font-weight:300 then light font will load.
Case 3 - font-weight:700 then bold font will load.

In your css file, add:
#import url('https://fonts.googleapis.com/css?family=Roboto:400,700');
at the top.
And, user it in the desired class like:
.class{
font-family: 'Roboto', sans-serif;
font-weight: 700;
}

Related

How to efficiently load google fonts in Nuxt

I am using this google font font-family: 'Saira Semi Condensed', sans-serif;
Link: https://fonts.google.com/specimen/Saira+Semi+Condensed
I am working in on a NuxtJS project. I have to use this font in two different components but with different font-weight. I have imported all the google fonts links in Layout.vue.
For component A the font-weight is 600 & for component B the font-weight is 800. So I thought giving different font-weights in the respective component will work. But it is not working. The only basic font has applied i.e. Saira Semi Condensed, sans-serif; but the font-weight values are not reflected. To resolve this problem I need import two google font links with the same fonts but different font-weight in Layout.vue which makes it redundant.
For font-weight: 600
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#600&display=swap%27);
For font-weight: 800
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#800&display=swap%27);
I think my way of importing two links for the same fonts is not look good. Can you guys please help me to solve this issue?
Thank you in advanced.
Code:
Layout.vue
<template>
<div>
<Nuxt />
</div>
</template>
<style>
#import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#600&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Saira+Semi+Condensed:wght#800&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#700&display=swap');
html {
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 16px;
word-spacing: 1px;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
</style>
index.vue
<template>
<div>
<Navbar />
<ComponentA />
<ComponentB />
<Footer />
</div>
</template>
<script>
import Navbar from '../components/Navbar.vue'
import Clock from '../components/ComponentA.vue'
import Days from '../components/ComponentB.vue'
import Footer from '../components/Footer.vue'
export default {
components: {
Navbar,
ComponentA,
ComponentB,
Footer,
},
}
</script>
ComponentA.vue
<template>
<div>
<h1>I am component A</h1>
</div>
</template>
<script>
export default {
name: 'ComponentA',
}
</script>
<style scoped>
footer {
color: blue;
font-family: 'Saira Semi Condensed', sans-serif;
font-size: 20px;
text-align: center;
}
</style>
ComponentB.vue
<template>
<div>
<h1>I am component B</h1>
</div>
</template>
<script>
export default {
name: 'ComponentB',
}
</script>
<style scoped>
footer {
color: red;
font-family: 'Saira Semi Condensed', sans-serif;
font-size: 24px;
text-align: center;
}
</style>
You're loading your fonts from a CDN, which is not the recommended way of doing things.
Here is a quote from this awesome performance checklist 2021 written by Vitaly Friedman
Now, many of us might be using a CDN or a third-party host to load web fonts from. In general, it’s always better to self-host all your static assets if you can, so consider using google-webfonts-helper, a hassle-free way to self-host Google Fonts. And if it’s not possible, you can perhaps proxy the Google Font files through the page origin.
Looking at this, I do recommend the usage of #nuxtjs/google-fonts, this is a cool Nuxt module.
I've actually asked if my configuration of the module was okay, here is the github issue: https://github.com/nuxt-community/google-fonts-module/issues/26
And here, a usage example in nuxt.config.js
export default {
buildModules: [
[
'#nuxtjs/google-fonts',
{
families: {
Mali: {
wght: [400, 600, 700],
},
},
subsets: ['latin'],
display: 'swap',
prefetch: false,
preconnect: false,
preload: false,
download: true,
base64: false,
},
],
]
}
And don't forget to also handle the #font-face CSS side of course!
PS: in case you have some issues of specific weights not being downloaded, you can use either overwriting: true in your module configuration or bump the package version to v3.0.0-1.

styling numbers with another font

I have a web page with a custom font in Arabic but numbers with that font appear in Arabic and not clear so I want to show it with Arial font (numbers only)?
I used that but not working :
#font-face {
font-family: Arial, Helvetica, sans-serif !important;
src: local("Arial"), local("Arial");
font-style: normal;
unicode-range: U+30-39;
}
You need to name your unicode-range specific font.
In sort I am instructing the browser to use test font for all applied glyphs, then fallback to Ballet
#import url('https://fonts.googleapis.com/css2?family=Ballet&display=swap');
#font-face {
font-family: 'test';
src: local("Arial");
font-style: normal;
unicode-range: U+30-39;
}
p {
font-size: 4em;
font-family: test, 'Ballet', cursive;
}
<p>Hi there! 1 2 3 4 5</p>
If I understand correctly you have to set the unicode-range to the #font-face declaration and then specify the font-family for the element (body, ...) where this font should be used:
I created two examples, one with arial and helvetica mixed and one with arial + Comic Sans MS mixed, since this is easier to see.
#font-face {
font-family: 'myNumbers';
src: local('Arial');
unicode-range: U+30-39;
}
p {
font-size: 2em;
}
.mixed {
font-family: myNumbers, Helvetica;
}
.mixedComic {
font-family: myNumbers, 'Comic Sans MS';
}
.arial {
font-family: Arial;
}
.helvetica {
font-family: Helvetica
}
<p class="mixed">
Hello, I am 123 and 456 with Arial for Numbers and Helvetica for Text
</p>
<p class="mixedComic">
Hello, I am 123 and 456 with Comic Sans MS as Text and Arial for Numbers
</p>
<p class="arial">
Hello, I am 123 and 456 in arial only
</p>
<p class="helvetica">
Hello, I am 123 and 456 in helvetica only
</p>

Newsletter HTML : fonts and vertical align

I'm creating an HTML newsletter. I'm using nested array. I have two question : how do I import font? Because #import and #font-face are not working on my newsletter (but works on simple html)
And the second is this :
How can I " vertical align middle " 2 span with different font-size ? It's working on simple html but not on the newsletter...
<table width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding:10px;">
<div>
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://" style="height:60px;v-text-anchor:middle;width:180px;" arcsize="17%" stroke="f" fillcolor="#00436f">
<w:anchorlock/>
<center>
<![endif]-->
<a href="#"
style="background-color:#00436f;font-weight:bold;border-radius:10px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:13px;text-align:center;text-decoration:none;width:180px;-webkit-text-size-adjust:none;padding-top: 25px; padding-bottom: 25px;"> <span style="font-size:2em;font-weight:bold;vertical-align:middle">15</span>
<span style="font-size:1.2em;font-weight:bold;text-transform:uppercase;vertical-align:middle">Février</span>
</a>
<!--[if mso]>
</center>
</v:roundrect>
<![endif]-->
</div>
<!--<p style="Margin: 0;font-size: 14px;line-height: 17px;width: 100%;padding: 25px 0;text-align: center;border-radius: 10px;background: #00436f;-->
<!-- color: white;">-->
<!--</p>-->
<p style="padding-top:10px;Margin: 0;line-height:1;font-size: 1em;font-weight:bold;color:#797979">Réunion d'information Loiret Numérique</p>
<p style="Margin: 0;font-size: 12px;line-height: 14px">
Mairie de Montargis - Salle Montdignan
</p>
</td>
</tr>
</tbody>
</table>
What I get:
What I need:
My fonts :
#media screen{
#import url("https://use.typekit.net/jqe0zpu.css");
#import url("https://www.site.fr/.../GT-Walsheim-Regular.ttf");
#font-face {
font-family: 'Walsheim';
font-weight: normal;
font-style: normal;
src: local("Walsheim"),url('https://www.site.fr/.../GT-Walsheim-Regular.eot');
}
#font-face {
font-family: 'Walsheim';
src: local("Walsheim"),url('https://www.site.fr/.../GT-Walsheim-Bold.eot');
src: url('https://www.site.fr/.../GT-Walsheim-Bold.ttf') format('truetype'),
url('https://www.site.fr/.../GT-Walsheim-Bold.woff') format('woff'),
url('https://www.site.fr/.../GT-Walsheim-Bold.woff2') format('woff2'),
url('https://www.site.fr/.../GT-Walsheim-Bold.eot?#iefix') format('embedded-opentype');
font-weight: 800;
font-style: normal;
}
}
As I mentioned in my comment, Outlook does not work with all web-fonts like Google fonts. You don't include full paths to resources so there is no way for us to test what you are doing and look for a solution.
My first suggestion is to open your email in a web browser and test to see if it works at all. If it does, then I suggest testing what you are doing in an Apple or IOS email client, since they seem to work well with web fonts. If it works, you know you have things coded correctly.
Generally an HTML document wih a web font needs a link to that font and applied in a class for use in the document.
You should have a link like this:
<style>
#import url("https://www.site.fr/.../GT-Walsheim-Regular.ttf");
</style>
Or this:
<link href="https://use.typekit.net/jqe0zpu.css" rel="stylesheet">
Next, you need to find some way to get the font out into the document.
<style>
.classname {
font-family: GT-Walsheim, Arial, sans-serif;
}
</style>
In the last example, I added Arial as a fallback font that is pretty web-safe because Walsheim is not going to work with Gmail and most likely not work with Outlook 2007, 2010, 2013-2019.
Finally, apply the classname:
<p class="classname">Hello</p>
You could go fancy and add in inline styles as well:
<p class="classname" style="font-family: GT-Walsheim, Arial, sans-serif;">Hello</p>
This is a very basic plan on how to work with web fonts in email.
Good luck.
Here is a simpler method of using div tags:
<style>
#import url('https://fonts.googleapis.com/css?family=Open+Sans');
#fevrier {
background: #00436f;
border-radius: 10px;
font-weight: bold;
color: #ffffff;
display: inline-block;
font-family: sans-serif;
text-align: center;
text-decoration: none;
width: 180px;
font-size: 16px;
font-weight: bold;
text-transform: uppercase;
vertical-align: middle -webkit-text-size-adjust:none;
padding-top: 25px;
padding-bottom: 25px;
}
#fevrier .text {
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
}
</style>
<div id="fevrier">
15 <span class="text">FÉVRIER </span>
</div>

How to make text thinner in CSS?

When I put in a <h1> tag, the text looks like it has been bolded.
How do we make text thinner in CSS?
Adjust your font-weight value: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
font-weight: normal
font-weight: bold
font-weight: lighter
font-weight: bolder
font-weight: 100
font-weight: 200
font-weight: 300
font-weight: 400
font-weight: 500
font-weight: 600
font-weight: 700
font-weight: 800
font-weight: 900
font-weight: inherit
CSS font-weight will do the trick. Here are some examples:
.font-weight-200 {
font-weight: 200;
}
.font-weight-300 {
font-weight: 300;
}
.font-weight-400 {
font-weight: 400
}
.font-weight-500 {
font-weight: 500
}
.font-weight-600 {
font-weight: 600
}
.font-weight-700 {
font-weight: 700
}
.font-weight-800 {
font-weight: 800
}
.font-weight-900 {
font-weight: 900
}
<h1 class="font-weight-200">font-weight: 200</h1>
<h1 class="font-weight-300">font-weight: 300</h1>
<h1 class="font-weight-400">font-weight: 400</h1>
<h1 class="font-weight-500">font-weight: 500</h1>
<h1 class="font-weight-600">font-weight: 600</h1>
<h1 class="font-weight-700">font-weight: 700</h1>
<h1 class="font-weight-800">font-weight: 800</h1>
<h1 class="font-weight-900">font-weight: 900</h1>
Read the MDN docs: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
Alternativly, you can just scale up a <p></p>. Example:
p {
font-size: 2rem;
}
<p class="thin-header">Some big thin text</p>
In case you didn't know, 2rem is 2 times the root font size, 3rem is 3 times the font-size, and so on.
Use font-weight:
div{/*pick your selector*/
font-weight: normal;
}
<p class="thin-text">Some text</p>
<style type="text/css">
.thin-text {
font-weight: 100;
}
</style>
Or, in-line:
<p style="font-weight: 100;">Some text</p>

#font-face not display for block items on MAC (Chrome/Safari)

I am having issues formatting any block elements with an embedded font in Safari and Chrome on a Mac.
Formatting is correct for all windows browsers (IE, Firefox, Chrome even Safari), and the font correctly displays for inline elements. I have stripped the html to just the following basics and still having this issue - What am I missing ??
#font-face { font-family: yowieFont; src: url(/template/GROBOLD.ttf); font-weight:normal; font-style:normal; font-variant:normal;}
h1 { font-family: yowieFont; color: #ed2249;}
h2 { font-family: yowieFont; color: #ed2249;}
h3 { font-family: yowieFont; color: #ed2249;}
p { font-family: yowieFont; color: #ed2249;}
span { font-family: yowieFont; color: #ed2249;}
<h1 style="display: inline;">1: CONTACT US</h1>
<h1 >1: CONTACT US</h1>
<h2 >2: CONTACT US</h2>
<h3 >3: CONTACT US</h3>
<p >P: CONTACT US</p>
<span>span: CONTACT US</span>
I resolved this issue by running the font through the font squirrel tool:
fontsquirrel.com/tools/webfont-generator
The tool generated the differing web formats required and fixed the line-height issues I was also having with this font
#font-face {
font-family: 'yowieFont';
src: url('/template/grobold-webfont.eot');
src: url('/template/grobold-webfont.eot?#iefix') format('embedded-opentype'),
url('/template/grobold-webfont.woff') format('woff'),
url('/template/grobold-webfont.ttf') format('truetype'),
url('/template/grobold-webfont.svg#groboldmedium') format('svg');
font-weight: normal;
font-style: normal;
}

Resources