Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

locally installed TTF overrides Google fonts

I'm using the Ubuntu font from Google Fonts:

<link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,300italic,400italic,500,500italic,700,700italic' rel='stylesheet' type='text/css' />

My stylesheet:

body {
    font-family: 'ubuntu',arial;
}

It works, but if install a font with the same name (Ubuntu), it overrides the one from Google Fonts.

Is it possible to force the browser to use the one from Google Fonts?

like image 383
Martin Avatar asked Feb 23 '12 19:02

Martin


1 Answers

The answer lies not in your code, but in Google's.

Here's part of the CSS you are requesting:

@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: bold;
  src: local('Ubuntu Bold'), local('Ubuntu-Bold'), url('http://themes.googleusercontent.com/static/fonts/ubuntu/v4/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff') format('woff');
}

Key line here is local('Ubuntu Bold'), which asks to load local file if possible. The simplest solution is to copy all the Google's CSS, paste it in your own CSS, and modify this local name to be, for example, local('Ubuntu Bold NonExisting Name or Something Else'). Such font does not exist and will not replace font loaded by CSS.

P.S. I have not tested this myself. If 0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff URL is expiring, then you are in a tough spot. Try to see font's licence and consider hosting the font yourself, if preventing local override is a priority.

like image 127
Jonas Lekevicius Avatar answered Oct 27 '22 07:10

Jonas Lekevicius