How do I fix "fallback" weight for different fonts? - html

I have a small, but immensely annoying problem.
I'm supposed to have a font-family for my h1, in the following fallback: BreeSerif, arial, sans-serif.
BreeSerif should be weight 400.
Arial should be weigth 700.
Sans-serif should be weight 400.
Now I have tried several things, but none seem to work.
First try:
This renders my BreeSerif to "normal", makes Arial to bold, BUT it seems impossible to render sans-serif to "normal" since I've declared the h1 to 700.
Second try:
Now since BreeSerif shall be normal, I could simply apply "sans-serif" to a #font-face and put it in font-weight: 700, but it doesn't work.
/* FIRST TRY */
#font-face {
font-family: 'BreeSerif';
src: url('fonts/BreeSerif-Regular.otf');
font-weight: 700;'
h1 {
font-family:
BreeSerif,
bold-arial,
sans-serif;
}
/* SECOND TRY */
#font-face {
font-family: 'BreeSerif';
src: url('fonts/BreeSerif-Regular.otf');
font-weight: 700;
#font-face {
font-family: 'sans-normal';
src: local('sans-serif');
font-weight: 700;
h1 {
font-family:
BreeSerif,
arial,
sans-serif;
font-weight: 700;
/* THIRD TRY */
#font-face {
font-family: 'BreeSerif';
src: url('fonts/BreeSerif-Regular.otf');
font-weight: 400;
#font-face {
font-family: 'arialBold';
src: local('arial');
font-weight: 700;
h1 {
font-family:
BreeSerif,
arialBold,
sans-serif;
font-weight: 400;
#font-face {
font-family: 'BreeSerif';
src: url('fonts/BreeSerif-Regular.otf');
font-weight: 700;
}
#font-face {
font-family: 'TradeWinds';
src: url('fonts/TradeWinds-Regular.ttf');
font-weight: 400;
}
}
#font-face {
font-family: 'sansnormal';
src: local('sans-serif');
font-weight: 700;
}
body {
width: auto;
background: #eee;
font-family: arial, sans-serif;
}
p {
font-family: helvetica;
font-size: 14px;
color: #222;
}
/* LÖS DENNA SEN! */
h1 {
font-family:
BreeSeri,
arial,
sansnormal;
font-weight: 700;
}
#ContentWrapper {
background: white;
width: 960px;
margin: auto;
}
Expected result: normal, bold, normal
Actual result: normal, bold, bold

Defining dimensions by using size-adjust for fallback fonts slowly hits mainstream according to:
https://caniuse.com/mdn-css_at-rules_font-face_size-adjust
See the current implementation percentage by today used browser
What does this mean?
You can use the following CSS definition:
#font-face {
font-family: 'Lato';
src: url('/static/fonts/Lato.woff2') format('woff2');
font-weight: 400;
}
#font-face {
font-family: "Lato-fallback";
size-adjust: 97.38%;
ascent-override: 99%;
src: local("Arial");
}
h1 {
font-family: Lato, Lato-fallback, sans-serif;
}
As you can see we define a fallback version of our webfont (in our case Lato) and this fallback version is just a refernce to "Arial", which is a safe web font. But with size-adjust we can tweak the size of the fallback font. The attribute ascent-override has the same implementation rate than size-adjust.
Getting the adjustment settings
But now you wonder, where do i get those adjustment sizes. This nice little page calculates them for you and gives you the complete CSS for the custom fallback font:
https://deploy-preview-15--upbeat-shirley-608546.netlify.app/perfect-ish-font-fallback/?font=Montserrat

Related

Font in footer changes despite footer already having CSS class declared

I have a design which uses DIV with flex, at https://jsfiddle.net/1s2mpba6/, but the main problem here relates to use of webfonts, one area, despite not having a webfont, seems to have been replaced even though the body font is used.
I get this when it should be Helvetica:
These are the areas of the HTML and CSS which seem to be problematic:
header.california-m {
background-color: #B22222;
border-radius: 10px;
color: #FFF;
padding: 30px;
width: 840px;
}
footer.california-m {
background-color: #333;
color: #FFF;
padding: 30px;
width: 840px;
margin-bottom: 20px;
}
footer.california-m h2 {
margin-left: 20px;
}
#font-face {
font-family: Fabriga Regular;
src: url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.eot?v=1.1.0");
src: url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.eot?#iefix&v=1.1.0") format("embedded-opentype"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.woff2?v=1.1.0") format("woff2"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.woff?v=1.1.0") format("woff"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.ttf?v=1.1.0") format("truetype"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Regular.svg?v=1.1.0#Regular") format("svg");
font-weight: 400;
font-style: normal
}
#font-face {
font-family: Fabriga Medium;
src: url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.eot?v=1.1.0");
src: url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.eot?#iefix&v=1.1.0") format("embedded-opentype"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.woff2?v=1.1.0") format("woff2"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.woff?v=1.1.0") format("woff"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.ttf?v=1.1.0") format("truetype"), url("https://c.atcdn.co.uk/fonts/ATFabriga-Medium.svg?v=1.1.0#Medium") format("svg");
font-weight: 400;
font-style: normal
}
#font-face {
font-family: ATVFabriga;
src: url("https://c.atcdn.co.uk/fonts/ATVFabriga.woff2") format("woff2");
font-weight: 400;
font-style: normal;
}
.columns-vehicleresult+h1,
h2,
h3 {
font-family: Fabriga Regular, Helvetica, sans-serif;
}
.columns-vehicleresult .column p.autog1 {
font-family: Fabriga Regular, Helvetica, sans-serif;
}
.columns-vehicleresult .column p.autog1 b {
line-height: 16px;
}
.atc-type-picanto {
font-family: ATVFabriga, Helvetica, sans-serif;
}
<footer class="california-m">
<h2>1 Anytown Road, Anytown 1</h2>
<h2>&phone; 555 0100</h2>
</footer>
However, I've not used a font-family for header or footer so why is this only happening to the footer and what do I need to fix?
Functionally, it works well, aesthetically, it's a small thing to fix, advice welcomed!
It should be in Helvetica as with the rest of the text for body declared in CSS, apart from the .columns-vehicle-result which use a webfont.
The content of your footer are two h2 elements, and the rule with selector .columns-vehicleresult + h1, h2, h3 applies to those.
If the formatting of that rule is supposed to only apply to headline elements that immediately follow a .columns-vehicleresult, for all three of those headline levels - then this would need to become
.columns-vehicleresult + h1, .columns-vehicleresult + h2, .columns-vehicleresult + h3 { }

Using Custom Font - Failed to decode downloaded font in Oracle Apex

I'm trying to use some customized font in my application.
So i tried downloading Pacifico and trying to use in my application. But getting Failed to decode downloaded font and the font is not loading
Below is my CSS .
#font-face {
font-family: 'MyWebFont';
src: url('#WORKSPACE_IMAGES#Pacifico.ttf') format('ttf');
}
body {
font-family: 'MyWebFont', sans-serif;
font-weight: 300;
line-height: 25px;
font-size: 14px;
}
This is not working. So i tried converting this to .woff as per suggestions found in web and tried below. Even this is failing. I'm using Chrome 74.0 version . How to solve this?
#font-face {
font-family: 'MyWebFont';
src: url('#WORKSPACE_IMAGES#Pacifico.ttf') format('ttf'),
url('#WORKSPACE_IMAGES#Pacifico.woff') format('woff'),
url('#WORKSPACE_IMAGES#Pacifico.woff2') format('woff2');
}
body {
font-family: 'MyWebFont', sans-serif;
font-weight: 300;
line-height: 25px;
font-size: 14px;
}
Problem here is you need upload the font into /i/
#font-face {
font-family: "Pacifico";
src: url("http://localhost:8080/i/Pacifico.ttf");
}
body {
font-family: "Pacifico", serif;
font-weight: 300 !important;
line-height: 25px !important;
font-size: 14px !important;
}
I don't know why Apex is not resolving the #WORKSPACE_IMAGES# but you can upload the font in the web server. In my case I'm using tomcat

CSS Fonts Not Working

So i'm trying to import a custom font located in /fonts/FONT.woff2 but when i add a new font family for it etc it just reverts the font to what i'm guessing is default ( Looks like Arial )
#font-face {
font-family: AvonValleyFont;
src: url(../fonts/FONT.woff2) format('woff2');
}
body {
background: #fff;
font-family: AvonValleyFont;
color:#4e4e4e;
line-height: 22px;
}
h5 {
font-size: 36px;
font-family: 'AvonValleyFont', 'Segoe UI', sans-serif;
}

More than 2 font weights per font family?

By default it is possible to implement different fonts, font weights and styles to be used later in my css styling:
#font-face {
font-family: "My Font Family";
src: url("fonts/my-font-family-regular.ttf");
font-weight: regular;
}
#font-face {
font-family: "My Font Family";
src: url("fonts/my-font-family-bold.ttf");
font-weight: bold;
}
Now I do want to add a light and a medium version:
#font-face {
font-family: "My Font Family";
src: url("fonts/my-font-family-light.ttf");
font-weight: 200;
}
#font-face {
font-family: "My Font Family";
src: url("fonts/my-font-family-medium.ttf");
font-weight: 500;
}
But this does not work for me. Is there a convention about the font weight values?
EDIT
If you want just one font name, you can set one font set weight using classes
#font-face {
font-family: "myFont";
src: url("fonts/my-font-family-light.ttf");
font-weight: 200;
}
.s1{
font-family: myFont;
font-weight: 200;
}
.s2{
font-family: myFont;
font-weight: 400;
}
.s3{
font-family: myFont;
font-weight: 600;
}
Otherwise, assign a different name for each element
#font-face {
font-family: "myLightFont";
src: url("fonts/my-font-family-light.ttf");
font-weight: 200;
}
#font-face {
font-family: "myMediumFont";
src: url("fonts/my-font-family-medium.ttf");
font-weight: 500;
}
Check w3schools for more info
Yes, There are different font-weight values and if you randomly use any value it will not reflect because they only give same result.
Like
if you give value (100 200 300 400 500 600 700 800 900)
then it will define font weight property thin to thick characters. 400 will be the same as normal and 700 will be the same as bold.
p.normal {
font-weight: normal;
}
p.light {
font-weight: lighter;
}
p.thick {
font-weight: bold;
}
p.thicker {
font-weight: 900;
}
Output :
Reference : Click Here

Use multiple #font-face rules in CSS

How can I use more than #font-face rule in my CSS?
I've inserted this into my stylesheet:
body {
background: #fff url(../images/body-bg-corporate.gif) repeat-x;
padding-bottom: 10px;
font-family: 'GestaRegular', Arial, Helvetica, sans-serif;
}
#font-face {
font-family: 'GestaReFogular';
src: url('gestareg-webfont.eot');
src: local('☺'),
url('gestareg-webfont.woff') format('woff'),
url('gestareg-webfont.ttf') format('truetype'),
url('gestareg-webfont.svg#webfontg8dbVmxj') format('svg');
}
This currently only applies for the whole body of text on the site. But, I would like to specify h1 to use a different font. How can I do this?
Note, you may also be interested in:
Custom web font not working in IE9
Which includes a more descriptive breakdown of the CSS you see below (and explains the tweaks that make it work better on IE6-9).
#font-face {
font-family: 'Bumble Bee';
src: url('bumblebee-webfont.eot');
src: local('☺'),
url('bumblebee-webfont.woff') format('woff'),
url('bumblebee-webfont.ttf') format('truetype'),
url('bumblebee-webfont.svg#webfontg8dbVmxj') format('svg');
}
#font-face {
font-family: 'GestaReFogular';
src: url('gestareg-webfont.eot');
src: local('☺'),
url('gestareg-webfont.woff') format('woff'),
url('gestareg-webfont.ttf') format('truetype'),
url('gestareg-webfont.svg#webfontg8dbVmxj') format('svg');
}
body {
background: #fff url(../images/body-bg-corporate.gif) repeat-x;
padding-bottom: 10px;
font-family: 'GestaRegular', Arial, Helvetica, sans-serif;
}
h1 {
font-family: "Bumble Bee", "Times New Roman", Georgia, Serif;
}
And your follow-up questions:
Q. I would like to use a font such as "Bumble bee," for example. How can I use #font-face to make that font available on the user's
computer?
Note that I don't know what the name of your Bumble Bee font or file is, so adjust accordingly, and that the font-face declaration should precede (come before) your use of it, as I've shown above.
Q. Can I still use the other #font-face typeface "GestaRegular" as well? Can I use both in the same stylesheet?
Just list them together as I've shown in my example. There is no reason you can't declare both. All that #font-face does is instruct the browser to download and make a font-family available. See: http://iliadraznin.com/2009/07/css3-font-face-multiple-weights
#font-face {
font-family: Kaffeesatz;
src: url(YanoneKaffeesatz-Thin.otf);
font-weight: 200;
}
#font-face {
font-family: Kaffeesatz;
src: url(YanoneKaffeesatz-Light.otf);
font-weight: 300;
}
#font-face {
font-family: Kaffeesatz;
src: url(YanoneKaffeesatz-Regular.otf);
font-weight: normal;
}
#font-face {
font-family: Kaffeesatz;
src: url(YanoneKaffeesatz-Bold.otf);
font-weight: bold;
}
h3, h4, h5, h6 {
font-size:2em;
margin:0;
padding:0;
font-family:Kaffeesatz;
font-weight:normal;
}
h6 { font-weight:200; }
h5 { font-weight:300; }
h4 { font-weight:normal; }
h3 { font-weight:bold; }
Multiple variations of a font family can be declared by changing the font-weight and src property of #font-face rule.
/* Regular Weight */
#font-face {
font-family: Montserrat;
src: url("../fonts/Montserrat-Regular.ttf");
}
/* SemiBold (600) Weight */
#font-face {
font-family: Montserrat;
src: url("../fonts/Montserrat-SemiBold.ttf");
font-weight: 600;
}
/* Bold Weight */
#font-face {
font-family: Montserrat;
src: url("../fonts/Montserrat-Bold.ttf");
font-weight: bold;
}
Declared rules can be used by following
/* Regular */
font-family: Montserrat;
/* Semi Bold */
font-family: Montserrat;
font-weght: 600;
/* Bold */
font-family: Montserrat;
font-weight: bold;