Can you change font-size if a font is not available?

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can you change font-size if a font is not available?

Post by simonmlewis »

I want to set a font to Gill Sans MT. Size 12.
But if the person does not have Gill Sans, then I set it to Arial or Verdana, but then the font is way bigger and doesn't look as good for this particular set of pages.

So, is there a way in CSS or PHP, where you can ask, if Gill Sans MT is NOT available, then use "font b", as size "11.2" for example???
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Can you change font-size if a font is not available?

Post by Christopher »

Search for "font stack" for more information.

Here is the first solution I found: http://stackoverflow.com/questions/8299 ... falls-back
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you change font-size if a font is not available?

Post by simonmlewis »

That page says it is not possible to set the font size as part of the "stack".
Is there a means in PHP to check if Gill Sans is working/available. Because then if it is NOT, then you can assign the font size to a different one. Easy.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you change font-size if a font is not available?

Post by simonmlewis »

http://www.lalit.org/lab/fontdetect.php
I cannot see how this page can be run, and then used via PHP.
So if that font is "true", then I can override the stylesheet to a set font, and if "false", use a different size.

Surely there is a way, since Gill Sans is smaller than Arial.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can you change font-size if a font is not available?

Post by requinix »

PHP runs on the server. The browser is on the client. You cannot use PHP to tell if the browser supports a font. Since there's no way with CSS you must use Javascript to do it.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Can you change font-size if a font is not available?

Post by Weirdan »

As another option Gill Sans is available as a web font from fonts.com for free (provided your traffic is less than 25k pageviews/month). They force you to display their banner though.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you change font-size if a font is not available?

Post by simonmlewis »

Is that done by pointing something to their server? Or something different?

Could I not just host the TTF file myself??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Can you change font-size if a font is not available?

Post by Weirdan »

You have to load some js code from their server. Self-hosted option is also available, but for a fee.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you change font-size if a font is not available?

Post by simonmlewis »

I did manage to download a OET Gill Sans file, but no idea how to make it work - that way you host the Gill Sans font, and use it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
annaharris
Forum Commoner
Posts: 30
Joined: Mon Mar 25, 2013 6:52 am

Re: Can you change font-size if a font is not available?

Post by annaharris »

No, As per my knowledge you can't change font-size if any particular font is not available.
Post Reply