Web design tutorials and resources for beginners

CSS3 Typography

The @font-face rule allows for linking to fonts that are automatically activated when needed. This permits authors to work around the limitation of “web-safe” fonts, allowing for consistent rendering independent of the fonts available in a given user’s environment. A set of font descriptors define the location of a font resource, either locally or externally, and the style characteristics of an individual face. Multiple @font-face rules can be used to construct font families with a variety of faces. Using CSS font matching rules, a user agent can selectively download only those faces that are needed for a given piece of text.  - W3C

 

CSS3 @font-face

  • The term web fonts generally refers to the use of @font-face.
  • @font-face allows you to specify which fonts are used within your site.
  • it eliminates the need for clunky and complicated workarounds.

 

@font-face Syntax

@font-face {
font-family: "My Font";
src: url("_assets/myFont.eot");
}

@font-face declarations are made at the top of stylesheets and give the user agent information needed to access and reference the font. In our sample rule, @font-face is used as the selector, and individual declarations are contained inside the rule’s brackets.

Font-family declaration: this defines a literal string which can then be referenced by font-family declarations when building font stacks.

Source declaration: This specifies the resource containing the font data. Usually a path to a font, although it can also contain links to external services. This declaration can also be a comma separated list that provides alternate resources for multiple devices.

 

Cross – browser Syntax

@font-face {
font-family: 'Graublau Web';
src: url('GraublauWeb.eot');
src: local('☺'),
url("GraublauWeb.woff") format("woff"),
url("GraublauWeb.otf") format("opentype"),
url("GraublauWeb.svg#grablau") format("svg");
}
  1. Declare the font-family as you would normally.
  2. Declare source for .eot font for Internet Explorer.
  3. Smiley face keeps local font matching issues from occurring.
  4. “Format/URL” syntax keeps Internet Explorer from downloading resources while other browsers continue until they find a supported font.
Font squirrel’s @font-face kits already includes this in a css file if you download fonts from their website. All you have to do is copy and paste, but if you change the location of the fonts make sure to update your source declarations.

 

Things to consider in using web fonts

  • Carefully consider how they are going to impact your design before using them.
  • Adds overhead to your site because this font resources need to be downloaded.
  • Heavy usage of web fonts often can cause a noticeable delay in the font rendering.
  • Make sure to test your design in several browsers.

Text Shadows

Text Shadow is broadly supported without the need for vendor prefixes, so text shadow is definitely one of the CSS3 techniques that we can use today.

 text-shadow: 1px 1px 3px #888; /* FF3.5+, Opera 9+, Saf1+, Chrome, IE10 */

First value is the x-offset it will move the shadow 5px over to the right. Second value is the y-offset it will move the shadow 5px down. Positive values will move the shadow to the right and down, Negative values will move it in the opposite direction. The third value is the level of blur. And the fourth value is the color.

Multiple Shadows

text-shadow: 0 0 2px #FFF, 0 0 5px #DDD, 0 0 10px #CCC;

The last one that you declare will be applied at the bottom. So the last is going to be really blurry with a darker gray color then it gets brighter as it goes inwards giving the illusion of a neon glow.

 

 

Related Posts

2 Comments

  1. Sir, what is better?
    Use @font-face, upload 4 fonts for cross-browser compatibility or use an image, in a sprite probably.

    Thanks.

    • It depends on the strictness of your requirement and browser support within your target audience, especially if you want to support mobile devices. Some of the benefits in using @font-face is its easier to maintain because you only need CSS to scale and style it and also 100% SEO friendly. But if you really need to make your text look exactly the same in all browsers and operating systems use an image replacement technique.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Choose a Rating

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>