Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google font not working with bootstrap

I'm trying to use Google Font on a page. In my html I used:

<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>

And in my CSS:

@import url('http://fonts.googleapis.com/css?family=Open+Sans');

Still whenI use "Open Sans" with the font-family attribute it stays on Arial.

body
{
    background-color: #F1F1F2;
    font-family: "Open Sans", Arial;
}
like image 811
user2820 Avatar asked Feb 10 '14 13:02

user2820


People also ask

How do I add Google Fonts to bootstrap?

Importing Your Web Font After you extract the zip file you generated above (or if you already have a webfont), right click the Fonts group in Bootstrap Studio and choose Import Webfont . In the file browser, navigate to the webfont and select the css file in the folder.

Can I use Google Fonts in CSS?

Of course you can style Google Fonts as you like, with CSS!


2 Answers

Using google font on any webpage is very easy and you can load the fonts asynchronously.

If you don't use the direct code that Google font delivers and you simply load the following url:

http://fonts.googleapis.com/css?family=Open+Sans:400,600

You'd be represented the source code (CSS).

Now, copy and paste the displayed code in the CSS source of your website.

You can then use your selected google font(s) on your webpages using the following:

body
{
    background-color: #F1F1F2;
    font-family: 'Open Sans', Arial;
}

That's enough and it will work.

like image 183
Ahmed Wild Avatar answered Sep 22 '22 16:09

Ahmed Wild


I have a hunch that your bootstrap is being loaded after the CSS for your Google font. Find the point that you are importing this CSS:

@import "bootstrap-sprockets"; @import "bootstrap";

Then add your Google code AFTER that to make sure that it is not being overwritten by the bootstrap.

Good Luck!

like image 45
DrewC Avatar answered Sep 23 '22 16:09

DrewC