Style Sheets
  Home arrow Style Sheets arrow Page 4 - Learn CSS, part 2: Units of Measurement
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Learn CSS, part 2: Units of Measurement
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 19
    2005-05-23

    Table of Contents:
  • Learn CSS, part 2: Units of Measurement
  • Using Pixels
  • Using em and ex
  • Using Percentage
  • Using Absolute Measurement Units

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Learn CSS, part 2: Units of Measurement - Using Percentage


    (Page 4 of 5 )

    With CSS you can use a percentage value for the font size property (as well as other properties, but here we are focusing on fonts). The percentage value is relative to the user's default font, so when you define a font size with the value 50 percent, and the default font size was 16px (like the Mozilla browser's default font size), you get an 8px font size. Let's see an example:

    body
    {
      font-family: Arial, sans-serif;
      color: red;
    }

    h1
    {
      font-size: 150%;
      background-color: aqua;
    }

    p
    {
      font-size: 80%;
    }

    Here is the HTML Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <link rel="stylesheet" href="paragraph.css" type="text/css">
        <title>Measurement Units with CSS</title>
      </head>
      <body>
        <h1>What's CSS?</h1>
        <p>
          CSS is a powerful formatting language for the web that is being used
    with markup languages like HTML, XHTML and XML and that's because the
    natural of the language. CSS uses the markup element name for applying
    formatting styles.
        </p>
        <h1>CSS and Markup Languages</h1>
        <p>
          You can't use css as a stand-alone styling language because you
    need something to style, like HTML or XHTML page.
        </p>
      </body>
    </html>
     

    When you open the Web page, you will get the following:

    We have defined a font size value of 150 percent for the h1 selector, which means 1.5 times the default font size, and we have set the value 80 percent to the font size property of the selector p, so we have 0.8 of the default font size. Note that the user can change the default font size, and the text will resize to accommodate the new size.

    More Style Sheets Articles
    More By Michael Youssef


       · It would have been worth noting in this article that absolute measurements in...
     

    STYLE SHEETS ARTICLES

    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables
    - CSS: Working with Text
    - CSS: Backgrounds
    - CSS for the Newbie







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway