Anyone know how I can include a google fonts style sheet in my rails app? I have tried adding
<link href='https://fonts.googleapis.com/css?family=Raleway:500,900,200' rel='stylesheet' type='text/css'>
Into my application.html.erb
but that doesn't do anything
Importing it into my Rails app was pretty easy. First, you create a folder called 'fonts' in your 'assets' folder. After that, you go shopping for fonts! After downloading one that catches your eye, simply drag it to your fonts folder.
For external style sheet add this to your layout (application.html.erb)
stylesheet_link_tag 'application', 'put any external link'
If you use
1) <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Font+Name">
in rails layout
2)
Style an element with the requested web font, either in a stylesheet:
CSS selector { font-family: 'Font Name', serif; }
or with an inline style on the element itself:
Your textyou got font family Tangerine
Example :--
<html> <head> <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> <style> body { font-family: 'Tangerine', serif; font-size: 48px; } </style> </head> <body> <div>Making the Web Beautiful!</div> </body> </html>
I was struggling with this one, because I had a line like this:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
It's hard to tell where to put your link at a first sight.
That you wanted to do is to place your stylesheet link AFTER 'application'
, divide it by commas. Like this:
<%= stylesheet_link_tag 'application', 'https://fonts.googleapis.com/css?family=Open+Sans:400&subset=latin', media: 'all', 'data-turbolinks-track' => true %>
Then use it in your stylesheet as usual with font-family property.
Of course, we can @import it in a SASS, or do it as usual with a link tag, but that's just an another way and it's should be mentioned here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With