Style Sheets
  Home arrow Style Sheets arrow Page 2 - 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

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


    (Page 2 of 5 )

    Web designers are accustomed to using the pixel unit to measure the font of text, as in the following example. Save the following CSS code into a file with the name Paragraph.css, and put it in the same directory as the HTML Web page.

    p
    {
      font-family: Arial, sans-serif;
      color: red;
      font-size: 15px;
    }

    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>
        <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>
      </body>
    </html>

     

    You will get the following results when you run the page.

    Actually, we did nothing more than use the font size property to define the size of the font as 15 pixels. Note that you must place the abbreviation of the unit right after its value, as we did in the above example (15px). Let's talk a little more about pixels. A pixel is a colored small square in the display area of your screen. Its size is not absolute; it's relative to the screen resolution.

    In other words, we can't know how many actual pixels are in one actual inch because pixels are relative to the screen resolution. If the screen resolution is 800 x 600, then a text that has been defined as 40px will be larger than the same text on a screen with 1024 x 768 resolution. This is because with the latter resolution, each row has 1024 dots (pixels) instead of 800, so the screen has to accommodate itself to the additional 224 pixels by dividing the display area by 1024 pixels (instead of 800). That means that the size of the pixel in the new resolution will be smaller than it was with an 800 x 600 screen resolution.

    The best use of the pixel unit is for positioning and layout elements, but not fonts. Microsoft Internet Explorer 5 and 6 can't resize the text (through the View Menu --> Text Size Sub Menu) if it's using pixels, and this is a drawback. Although Mozilla can resize text that uses pixels, Microsoft Internet Explorer has more than 80 percent of the browser market; we can't just ignore that. So try to use pixels for positioning your elements, and avoid using it for styling fonts and printing documents.

    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 1 hosted by Hostway