Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Casey Ydenberg
Casey Ydenberg
15,622 Points

media query for if a Google font won't load?

I'm using a Google font, but my site looks weird without it; the title line overflows it's container if the font doesn't load.

Granted this isn't likely to happen once I post the site, since I'm developing locally it occurs when my connection lapses. What are the standard workarounds, or is this not worth worrying about?

5 Answers

Kevin Korte
Kevin Korte
28,149 Points

As far as I know, you can't change the font size based on what font is being used. There might be some way in JavaScript to tell what font was applied and then apply a font size to that font, but that becomes complicated, and going back to the idea that your website should look as good as possible if it's shown as barebones, if your user had Javascript disabled, than that option would clearly break and we are back to square one.

I think the problem is your font family is not consistent. I googled the fonts and say that Mr Dafoe is a tight, small cursive font, while Trebuchet MS is a nice bold sans-serif font, and your fallback is also sans-serif.

IMO you have 3 feasible options.

You can leave it as is and hope that google doesn't make any changes to it's font service, and in particular the fonts you are pulling from them.

You can ditch the Mr. Dafoe and use a selection of fonts that are all sans-serif.

You can ditch the Trebuchet MS and sans-serif fallback, and pick a cursive style font family. Your font-family could be as simple as "Mr Dafoe", cursive.

Kevin Korte
Kevin Korte
28,149 Points

How exactly are you bringing in the google font? It sounds like you are using the @import method?

I prefer using the standard way, linking in their stylesheet, and then adding the font family to the text I want to style.

But you DEFINITELY want the font to still look good and fit correctly even if it's fallen all the way back to the web browsers default serif or sans-serif font.

If google decides to drop that font, or move it, or change it's name, or drop their font service all together, than your page will not look right. Don't rely on somebody else's service to make your site look good. It should still look good and function correctly even if all your plug-ins and styling updates break.

Casey Ydenberg
Casey Ydenberg
15,622 Points

I'm linking to the stylesheet, but the link is external.

<link href='http://fonts.googleapis.com/css?family=Mr+Dafoe' rel='stylesheet' type='text/css'>

Then in my main stylesheet I've got:

h1 {
    font-family: "Mr Dafoe", "Trebuchet MS", sans-serif;
}

Thanks for your input - what can I do? Can I change the font-size property based on what font it ends up using?

Casey Ydenberg
Casey Ydenberg
15,622 Points

I see. I chose to fall back to sans-serif instead of cursive because the default cursive fonts all look crappy (Comic Sans or something similar to it). But I get that the problem comes from mixing font types.

I'll play around with other solutions, thanks for your help.

Kevin Korte
Kevin Korte
28,149 Points

Yeah, dreamweaver kicked back the default fonts as being comic sans MS, than cursive, which just the font type cursive on my firefox is still comic sans ms...yuck.

On other idea, but it has a downside too.

I assume you're not writing a paragraph in this cursive font, just a title or headline or something? You could that text in as an image. The image of text should load very consistently, with the web file and image living on the same server, you're not depending on another outside service or plugin.

The problems are SEO, screenreaders, and what if the image doesn't load by chance. You can give the image of text an Alt tag of what it said. That will display if the image doesn't, it'll also help with SEO issues (although not a perfect solution). I don't know for sure if screen readers pick up alt tags or not. But you could add the same text in right before or after the image, and than give that text a huge text indent, like -9999px, which will keep it off of every screen, but a screen reader should still pick it up since it is in your code.

Good luck whatever you decide to do. It's ultimately up to you!