CSS: import and use different fonts

Posted by RobElliott on 30 Sep 2012 08:16, last edited by Helmut_pdorf on 04 Sep 2015 07:55

: css

rating: +22

Most websites use "web safe" fonts which are fonts installed on all computers. However there are hundred or thousands of more interesting typefaces which you can now use with your Wikidot site. There are two ways to use other fonts, either from Google WebFonts which has over 500 available or a slightly more complex method from Font Squirrel if the font you want is not on Google Web Fonts.

Google Web Fonts

Go to http://www.google.com/webfonts

1. Find the font you want to use and click on the Add to Collection button.

2. Click the Use button in the bottom right of the screen then scroll down.

3. If there are a number of different variations check the checkboxes next to the one(s) you want to use.

3. Where you see the "Add this code to your website" click the @import button and copy the code,
for example @import url(http://fonts.googleapis.com/css?family=Architects+Daughter); to your main CSS.

Note:

4. Scroll further down the google webfonts page you then need to integrate the font-family into your CSS. So copy the code there, for example font-family: 'Architects Daughter', cursive; to the relevant rule in your main CSS. For example

#page-title {
 font-family: 'Architects Daughter', cursive;
}

What this means is that for the page title the Architects Daughter font will be used, but if for some reason the google webfonts api is not working then the web safe font of cursive will be used instead, so there is a falback.

Using your own font with a css module

If you only want to use the font on one page or in a category you can use a css module on your page or in your live template page, for example::

[[module css]]
@import url(http://fonts.googleapis.com/css?family=Architects+Daughter);
#page-title {
 font-family: 'Architects Daughter', cursive;
}
[[/module]]

Font Squirrel

If the font you want to use is not available at Google webfonts you can use fonts from Font Squirrel or upload your own fonts there and generate the code to you in your own site. It works well but is more complex than Google webfonts.

1. Go to http://www.fontsquirrel.com/fontface/generator

2. select the Expert option radio button.

3. Select the base64 encode checkbox.

4. Then upload the font you want to use. Once you have checked the agreement checkbox click on the Download Your Kit button at the bottom. It will download a zip file to your computer containing several font files and a CSS stylesheet. Upload the font files to the css page on your computer and copy the css from the stylesheet to a different page on your site inside [[code type="css"]] .. [[/code]] tags.

It needs to be a on a separate page because the css code is very long and you risk exceeding the 200,000 character limit if you put it into your main css page.

You will then need to import the css from that page to your main css using the @import rule. It must be the first rule in your css. I have done this in the example below where the code was put on the css:architect page. When using the @import rule you don't need the full http://… address, you can use a relative url as I have done below:

[[code type="CSS"]]
/* IMPORT HEADER FONT
=============================*/
@import url(/css:architect/code/1);
.....the rest of your css goes here....
[[/code]]

You then need to specify in your main css which elements are using the font-family you have imported and any fallback fonts. For example:

#header h1 a, #header h1 a:hover, #header h2 a, #header h2 a:hover{
 color:#000000;
 font-family: "ArchitectRegular", verdana, arial;
 font-size:60px;
}

Using your own font with a css module

You can put the CSS code downloaded from Font Squirrel into a css module on your page. This is not ideal as the code is very long and you will risk exceeding the 200,000 character limit on the page.


Live Examples

import-fonts.jpg

A live site where both methods has been used is at http://gtr.wikidot.com and an image from that site is shown on the left

* the font for the normal text, headings etc is "Open Sans" and was imported from Google Webfonts
* the font for the top bar menu is "FGJayne" and was generated at Font Squirrel.

The CSS for that site where you can see how the fonts have been used in the CSS is at http://gtr.wikidot.com/css:theme. You will see that the FGJayne font generated at Font Squirrel is imported into the main css from its own page on the site which holds the font files and the font code.

Another example is http://www.wdeditor.com where Shane (leiger leiger ) has used the Pontano Sans font from Google Web Fonts to good effect.


Note on font support by browsers:

  • Firefox supports OTF and TTF
  • Internet Explorer only supports EOT
  • Safari and Opera support OTF, TTF and SVG
  • Chrome supports TTF and SVG.

Related articles

Comments

Love it Rob!
GoVegan GoVegan 30 Sep 2012 09:54

Love this article Rob! Embedding fonts is a very exciting web innovation that we should all take advantage of.

Small request: Could you please give us an example of a non-standard font working in action? That would be cool!

by GoVegan GoVegan , 30 Sep 2012 09:54
RobElliott RobElliott 30 Sep 2012 10:11

I have added a link to a live example at http://gtr.wikidot.com where the normal text, headings etc are imported from Google Webfonts and the top bar menu font was generated at Font Squirrel.

Shane's site at http://wdeditor.com also makes good use of the Pontano Sans font imported from Google Web Fonts.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

Last edited on 30 Sep 2012 13:24 by RobElliott
by RobElliott RobElliott , 30 Sep 2012 10:11
GoVegan GoVegan 30 Sep 2012 10:24

Soooooooooo cooooooooool !!!!!!!!!!

by GoVegan GoVegan , 30 Sep 2012 10:24
RobElliott RobElliott 30 Sep 2012 10:34

Well thank you kind sir.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

by RobElliott RobElliott , 30 Sep 2012 10:34
Printing...??

Well I got it working on my wikidot site, but I was hoping you could also print it.
Bummer for now, even your greentea site… if you print it the typeface is gone.

We have to investigate on this and extend the tutorial if it is also possible to print.


A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.

by Steven Heynderickx Steven Heynderickx , 13 Nov 2012 22:18
How to apply a font to everything on a site?
talegari talegari 02 Jan 2015 07:12

Thanks for the article.

The changes in the CSS seem specific. The font does not appear in 'Table' or 'bulleted points 'environment, for example. Is there a way to use a font everywhere on a site?

Last edited on 02 Jan 2015 07:14 by talegari
by talegari talegari , 02 Jan 2015 07:12
RobElliott RobElliott 02 Jan 2015 10:20

The font does not appear in 'Table' or 'bulleted points 'environment, for example.

No it won't if you have just applied the font to specific elements, as I did in my example to the headers.

If you want the same font to be used everywhere on a site or category then add a html * rule at the beginning of your CSS and make sure there are no font-family properties anywhere else in your CSS.

Import the font you want to use and place the import as the first thing in your CSS. Then add the html * rule and apply the font:

[[code type="css"]]
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
html * {
 font-family: "Open Sans";
}
...any other css goes here...
[[/code]]

You can the result of that at http://vineyard.wikidot.com/client:peter-gabriel where everything has been set to the Open Sans font.


Rob Elliott - Strathpeffer, Scotland - Wikidot first line support & community admin team.

Last edited on 02 Jan 2015 10:57 by RobElliott
by RobElliott RobElliott , 02 Jan 2015 10:20
css
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /