How to set custom font in whole Vaadin 7 application - css

I defined custom font for my application because by default characters like 'č' did render with Arial font while rest of application rendered with "Open Sans Light". In styles.scss:
#include v-font('LocalFont', '../../../../mytheme/fonts/open-sans-v15-latin-ext_latin-300');
...
...
From rendered webpage I see font family used depends on styles.css:
.mytheme.v-app, .mytheme.v-app-loading {
font: 300 16px/1.55 "Open Sans", sans-serif;
but I see no way affecting it. In mytheme.scss within #mixin mytheme { I tried to define:
.v-app, .v-app-loading {
font: 300 16px/1.55 LocalFont, sans-serif;
}
.mytheme.v-app, .mytheme.v-app-loading {
font: 300 16px/1.55 LocalFont, sans-serif;
}
but in styles.css it is build as:
.mytheme .v-app, .mytheme .v-app-loading {
font: 300 16px/1.55 LocalFont, sans-serif;
}
.mytheme .mytheme.v-app, .mytheme .mytheme.v-app-loading {
font: 300 16px/1.55 LocalFont, sans-serif;
}
and that will not use my local fonts (unless I remove spaces after .mytheme).
Is there a way to affect font family in .mytheme.v-app, .mytheme.v-app-loading {?
As a workaround I defined this in my theme:
.v-ui{
font: 300 16px/1.55 LocalFont, sans-serif;
}
.v-tooltip{
font: 300 16px/1.55 LocalFont, sans-serif;
}
.v-window{
font: 300 16px/1.55 LocalFont, sans-serif;
}
.v-Notification{
font: 300 16px/1.55 LocalFont, sans-serif;
}
This covers probably all cases, but I am not sure if vaadin could add element that is direct child of element with v-app css class and uses other css class. Is this workaround applying to all cases - does vaadin use other css classes that are direct child of v-app class?
Notes:
Vaadin documentation only states to use font family in my styles.
I am using server fonts because application is behind proxy and using web fonts for rendering characters like 'č' fails because some clients have no access outside application server.
Initally I tried to define my fonts in styles.scss like:
#include v-font('Open Sans', '../../../../mytheme/fonts/open-sans-v15-latin-ext_latin-300');
...
#include v-font('Open Sans Light', '../../../../mytheme/fonts/open-sans-v15-latin-ext_latin-300');
...
But it did not used my fonts for rendering 'č', not sure why.

So.. if you've called your theme: my-theme
In the file: my-theme.scss
You need to add at the top the file: $v-font-family: "Open Sans", sans-serif;
Here's a link to the other Valo Theme variables

This Question is about the older version 7 of Vaadin. Here's an Answer for those with the same need in current Vaadin 14.
Vaadin Flow
The newer generation of Vaadin version 10 and later is known as Flow. This revamp of Vaadin now uses the Lumo theme by default. The theme is designed to be easy to alter, changing font, size, color, spacing, and so on.
The Vaadin team now offers an online editor to make changing the theme easy, with a palette of settings to tweak, and a visual display to see the effects. When you are satisfied, you can download the theme settings for use in your Vaadin project.
In particular, on the Typography tab with its Font family pop-up menu, you can choose a default font for the entire app. For finer control of your Web typography, you can open the Advanced section to edit the CSS font stack.
By the way, Lumo has both a light and a dark mode, the dark shown here.

Related

Is it valid to replace system fonts via #font-face in CSS?

Today, I stumbled across a CSS hack that works in my current browser:
When an element uses a system font, like "Courier", then I was able to define a custom #font-face to replace the Courier font with a custom web font.
It's working for me; however, before using that kind of CSS on customer websites I'd like to understand if this is intended browser behavior, or a glitch that might disappear any time or is not even supported on some devices.
.demo {
padding: 10px;
background: #eee;
}
/*
My Font Hack: Replaces Courier with "Roboto" Google Fonts
*/
#font-face {
font-family: Courier;
src: url(https://fonts.gstatic.com/s/raleway/v28/1Ptug8zYS_SKggPNyC0IT4ttDfA.woff2) format('woff2');
}
<div class="demo" style="font-family: Courier!important">
This is Courier
</div>
It doesn't replace anything, it just changes alias for the Courier font string for the current page where CSS is loaded in.
The reason you shouldn't do this not because of browser incompatibility/glitch, but because it changes semantics of "font-family: Courier!important" and down the line will make debugging font-related problems harder.

SF Pro Display looks different to native Apple System Font - kerning (letter-spacing) doesn't match

I installed the SF Fonts from https://developer.apple.com/fonts/ but when I install and use them, they look different from the native "apple-system" fonts when setting the body font-family in the CSS. When I change this to use "SF Pro Display", the letters look much closer together.
/* Using downloaded font: */
body {
font-family: 'SF Pro Display';
}
/* Using native font: */
body {
font-family: -apple-system, 'system-ui';
}
On closer inspection, Chrome renders the font: .SF NS Display—Local file(10 glyphs)
Is this a different font completely? Seems strange that this isn't included in the Developer font download. However the main difference seems to be the letter-spacing.

Scaling one font face in CSS

I'm writing a tiny website for a book that's currently being printed, and want to match the slightly eccentric font called Cronos Pro which it uses for its headings. I'm currently doing this with the following CSS:
header, h1, h2, h3 {
font-family: cronos-pro, sans-serif;
}
Cronos Pro is supplied using our Adobe Creative Cloud subscription, and under the terms of their licence this must be loaded as follows:
<link rel="stylesheet" href="https://use.typekit.net/xxxxxxx.css"/>
This just produces a set of #font-face rules defining the font, and it all works fine. Nevertheless, I feel I ought to keep the fall-back of sans-serif in case the font is temporarily unavailable, or for an old browser that doesn't support it.
However, Cronos Pro is a very compact font. If I know the browser is using it, I want it rendering bigger, as if I'd added font-size: 125% to the CSS. But if the browser falls back to its default sans serif font, I want it at 100% size.
I thought I could do this as follows, but Firefox tells me it's an invalid property value:
font: cronos-pro 125%, sans-serif;
Is there a good way of achieving this, bearing in mind the #font-face rule is outside of my control?
You could use JavaScript to add a stylesheet with your font-size: 125% tag if and when Chronos Pro loads successfully:
<script>
{
let font = "cronos-pro";
let styleSheet = document.createElement('style');
document.head.appendChild(styleSheet);
document.fonts.ready.then(function () {
if( document.fonts.check(`1em ${font}`) ){
styleSheet.sheet.insertRule('header, h1, h2, h3 { font-size: 125%; }')
}
});
}
</script>
Not sure if this is a "good way" to do it, but it should work in a pinch.  I'm still a bit new at web development.

Changing font-family from Segoe to Futura (Bulma)

I'm working from a template that uses Bulma and the default font is set to Segoe UI. However, I'm trying to change the default font in headers to futura-pt-bold.
Here is the place in the all.sass file where I am trying to assign the new font-family (the headers are all in div containers with class "content"):
#import "~bulma"
.content h1, h2, h3, h4
font-family: futura-pt-bold !important
font-style: normal
But it's still picking Segoe UI instead of Futura pt. I've tried "Futura," "Futura PT," etc but nothing seems to work.
I am using Firefox and so far am only running the web app locally.

Impossible to copy light font?

I tried to copy the font of this website menu but when I put the style in my own WordPress CSS theme I still get the bold version of it. Is there a special trick so I can get the light version of the font?
Got the font the same way loaded in what they have.
If you are indeed looking for the font Montserrat and you want the light version, you can use this import reference:
#import url(http://allfont.net/allfont.css?fonts=montserrat-light);
And you can use it like this in css:
font-family: 'Montserrat Light', arial;
More information about this font can be found here: http://allfont.net/download/montserrat-light/
It looks like the Google font Montserrat:
http://www.google.com/fonts/specimen/Montserrat
It seems this font only comes in Normal (400) and Bold (700):
http://www.google.com/fonts#UsePlace:use/Collection:Montserrat
For the Normal version of the font, try adding:
font-weight: 400;
to your CSS. Also, make sure you're referencing the font correctly by importing it first:
#import url(http://fonts.googleapis.com/css?family=Montserrat);
then adding the style to the correct element:
font-family: 'Montserrat', sans-serif;

Resources