Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using @font-face

From: HTML5 First Look

Video: Using @font-face

Now that we know a little bit more about @font-face, let's use it on our trail guide page to enhance our design. Now I want to point something out that's really, really important about this. Due to licensing issues your exercise files do not contain the fonts that I'm going to be using. If you didn't watch the previous movie, which contains instructions on how to download and save the files for this exercise, please go back and do that now. Once you've downloaded those fonts, and if you want to use a different font-family that's fine by me, feel free to do any font-family you want, but once you've downloaded them, here is where you need to place them.

Using @font-face

Now that we know a little bit more about @font-face, let's use it on our trail guide page to enhance our design. Now I want to point something out that's really, really important about this. Due to licensing issues your exercise files do not contain the fonts that I'm going to be using. If you didn't watch the previous movie, which contains instructions on how to download and save the files for this exercise, please go back and do that now. Once you've downloaded those fonts, and if you want to use a different font-family that's fine by me, feel free to do any font-family you want, but once you've downloaded them, here is where you need to place them.

Go in the Chapter_07 folder, you are going to look in the set 07_06/_assets and you're just going to place them there. So you can see in that folder currently I have got all of those font types for both ChunkFive and Mido that I got from Font Squirrel, so you want to go ahead and grab those as well. I'm also going to advise you, if you did the @font-face kits that I was talking about in the previous movie, go ahead and open up the CSS for that and copy the @font-face for both of those. It's so much easier than typing it yourself.

You're not as prone to make mistakes and I am going to be copying and pasting a little bit myself here too, just to keep this video from being 20 minutes long. But I'm going to go overall the syntax for you guys, so that you understand kind of what's happening. Now speaking of that, you'll notice that I have the main.css file open from the 07_06/_css file. You also want to have the trails.htm file open, because that's the one that you are going to be testing. All right, so I have got my main.css open and what I am going to do is just below the color guide of the styles but above the limited reset, I am going to go ahead and do both of my @font-face declarations.

See how easy that is? That's really easy if we're copying and pasting. But let's go over everything in case you are not. So we do an @font-face declaration, inside of that we do font-family and then we type in what we want to call this font within our styles. Just because Font Squirrel did MidoMedium and ChunkFiveRegular, it doesn't mean that I have to. I could just do Mido if I wanted to. I could call it Chunk if I wanted to. This is totally up to you, but it is how you're going to reference the fonts later on. So make sure you use something that's easy for you to remember and easy to spell, easy to type, that sort of thing.

Now I want to point out one thing here that is very different than the Font Squirrel syntax. You'll notice that I have appended to the front of these ../_assets. That's because this is the location of the font resources that we are going to be accessing for our files. So if you are going to host these up on your own server, you need to go ahead and make sure that the path to the font formats themselves point to the proper location. Also notice that copying and pasting allowed me to use the smiley face, because I don't know how to type that in using the keyboard.

If anybody does know that you can send me an email. I would love to learn that. So other than that we have our font formats here. So after the eot, which remember Internet Explore is going to use this one, we use the syntax that Internet Explorer does not understand, which is to split the URL and the format declaration. Notice that these are separated by commas and one source property. So we have a comma then we do a truetype, then we do another comma and then we do our svgs. You will also notice they follow up with the font way in a font style, which essentially just tells browsers, just gives them the default styling and saying we are going to use the normal version of both of these fonts.

Okay, so obviously that can take a little bit of time to type out. You can sort of pause the video and type those out, but again, if you've downloaded those from Font Squirrel you can just copy and paste them yourself. Okay, so now that we know that, let's take a look at how we actually use this in our styles. What I am going to do is just scroll down and I am going to find the header section in the presentational styles. So here we are around line 89 or so, and so what I want to do is I want to find the header#mainHeader ul li a, and for me it's about one line 118. It's right there.

And what I am going to do is create a blank line at the very top of this. It doesn't have to be at the top, but I would like to put my font declarations there, and I am going to type in font-family and then I am going to do a font-family declaration unlike the normal ones I do. I am going to do ChunkFiveRegular. So spelling obviously counts here and so does capitalization. So ChunkFiveRegular. I am going to follow that up with 'Arial Black', Arial, serif. Now that's just me saying okay, if ChunkFiveRegular for some reason doesn't work or is not available, go ahead and use Arial Black.

If you don't support that, go to Arial. If you don't support that just give me your normal serif font. Now there is no needed to for me to type this over again. I am just going to copy this, or you could save it in a snippet if you'd like, and I am just going to paste it wherever I need this particular font. So I am going to stay in the main header region and I am going to find the hgroup h1 selector here, h1, hgroup that's the main headline on the page. I am going to paste that in and I am going to do one more thing to this one. I am going to do a text-transform property and I am going to transform it to uppercase, so that the main headline is in all caps.

It will make it look really cool, especially with this particular font. I am going to stay in the mainHeader group and I am going to go down to the very next selector, which is the h2 selector. Well, actually you know what? I am going to skip that, because that one I am going to use Mido for and I have got this in my clipboard, so I want to just keep going down to the ones that need ChunkFive. So I'm going to go down to the trailinfo article. So trailinfo article h1, that's the selector I want next, this one is on about line 165 at the moment. I'll paste that one in, and then finally I am going to go down to the aside styles.

I am looking for the aside#trailNews h1, which is right here on line 227 at the moment, and I am going to paste that. Okay, cool. So now all of our ChunkFive ones are done. I now need a couple of them that are going to be Mido. So I am going to go back up into my header grouping. I am going to find my mainHeader hgroup h2. That's the tagline and right at the top of that, I am going to do another font-family declaration, and this one is going to be MidoMedium, Georgia, serif.

So again, just giving myself some fallback options. I will copy that one as well. I am going to scroll down to my section# trailInfo caption, so I need to to find my caption, there it is, and inside caption here I am going to do another font-family declaration, and I am just going to do Mido, there we go. So I will save that and I am going to test this in my browser. I can test this in any modern compliant browser and there we go. So you will notice we now have our links are styled using ChunkFive. There is our main headline. There is our Mido in the tagline. You will notice there are Rider Reviews, Trail News, Northridge Loop are using the ChunkFive and our caption is using Mido as well. So cool! Our page is now using our new fonts, and we did that without needing any JavaScript or any type of third-party plug-ins.

Yeah, I agree the workarounds and all that syntax that you have to do for browser support are a little bit tedious, but I'll be honest. It's a lot less complicated than many of the alternatives, and I got to mention, as you can see, our page looks great.

Show transcript

This video is part of

Image for HTML5 First Look
HTML5 First Look

50 video lessons · 74410 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 3m 56s
    1. Welcome
      1m 1s
    2. Using the exercise files
      1m 50s
    3. Who is this course for?
      1m 5s
  2. 21m 12s
    1. Exploring prior standards
      4m 26s
    2. Why do we need HTML5?
      3m 32s
    3. HTML5 timeline
      4m 24s
    4. Current HTML5 support
      4m 25s
    5. What HTML5 is (and what it isn't)
      4m 25s
  3. 27m 49s
    1. HTML5 vs. HTML4
      3m 25s
    2. New structural tags
      6m 1s
    3. New content tags
      4m 7s
    4. New application-focused tags
      5m 32s
    5. Deprecated elements
      4m 28s
    6. API overview
      4m 16s
  4. 22m 29s
    1. Content models
      5m 33s
    2. Understanding the outline algorithm
      3m 21s
    3. The role of ‹div› tags
      4m 20s
    4. Using ID and class attributes
      2m 6s
    5. DOCTYPE declarations
      4m 16s
    6. Character encoding
      2m 53s
  5. 41m 27s
    1. Basic page structure
      3m 40s
    2. Structuring top-level elements
      7m 30s
    3. Structuring interior content
      8m 42s
    4. Building headers
      9m 11s
    5. Checking document outlines
      5m 46s
    6. Ensuring cross-browser structure
      6m 38s
  6. 27m 53s
    1. New input types
      5m 57s
    2. Setting form autofocus
      2m 53s
    3. Using placeholder data
      4m 4s
    4. Marking required fields
      3m 24s
    5. Working with number inputs
      5m 49s
    6. Using date pickers
      5m 46s
  7. 1h 1m
    1. Canvas overview
      6m 21s
    2. Adding canvas content
      8m 58s
    3. Drawing in the canvas environment
      12m 9s
    4. Drag-and-drop API overview
      6m 18s
    5. Offline applications overview
      7m 11s
    6. Video overview
      5m 45s
    7. Encoding video
      8m 23s
    8. Adding video
      5m 58s
  8. 57m 33s
    1. Geolocation API overview
      5m 50s
    2. Web storage API overview
      5m 40s
    3. WebSockets overview
      4m 16s
    4. CSS3 overview
      6m 38s
    5. Enhancing typography with CSS3
      7m 42s
    6. Using @font-face
      7m 11s
    7. Styling HTML5 with CSS3
      10m 23s
    8. Using CSS3 transitions
      9m 53s
  9. 5m 6s
    1. Final thoughts
      3m 49s
    2. Goodbye
      1m 17s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML5 First Look.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.