All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.w3c.css.values.CssLength

java.lang.Object
   |
   +----org.w3c.css.values.CssValue
           |
           +----org.w3c.css.values.CssLength

public class CssLength
extends CssValue

   Length units

The format of a length value is an optional sign character ('+' or '-', with '+' being the default) immediately followed by a number (with or without a decimal point) immediately followed by a unit identifier (a two-letter abbreviation). After a '0' number, the unit identifier is optional.

Some properties allow negative length units, but this may complicate the formatting model and there may be implementation-specific limits. If a negative length value cannot be supported, it should be clipped to the nearest value that can be supported.

There are two types of length units: relative and absolute. Relative units specify a length relative to another length property. Style sheets that use relative units will more easily scale from one medium to another (e.g. from a computer display to a laser printer). Percentage units (described below) and keyword values (e.g. 'x-large') offer similar advantages.

These relative units are supported:

   H1 { margin: 0.5em }      /* ems, the height of the element's font * /
   H1 { margin: 1ex }        /* x-height, ~ the height of the letter 'x' * /
   P  { font-size: 12px }    /* pixels, relative to canvas * /
  

The relative units 'em' and 'ex' are relative to the font size of the element itself. The only exception to this rule in CSS1 is the 'font-size' property where 'em' and 'ex' values refer to the font size of the parent element.

Pixel units, as used in the last rule, are relative to the resolution of the canvas, i.e. most often a computer display. If the pixel density of the output device is very different from that of a typical computer display, the UA should rescale pixel values. The suggested reference pixel is the visual angle of one pixel on a device with a pixel density of 90dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is about 0.0227 degrees.

Child elements inherit the computed value, not the relative value:

   BODY {
     font-size: 12pt;
     text-indent: 3em;  /* i.e. 36pt * /
   }
   H1 { font-size: 15pt }
 

In the example above, the 'text-indent' value of 'H1' elements will be 36pt, not 45pt.

Absolute length units are only useful when the physical properties of the output medium are known. These absolute units are supported:

   H1 { margin: 0.5in }      /* inches, 1in = 2.54cm * /
   H2 { line-height: 3cm }   /* centimeters * /
   H3 { word-spacing: 4mm }  /* millimeters * /
   H4 { font-size: 12pt }    /* points, 1pt = 1/72 in * /
   H4 { font-size: 1pc }     /* picas, 1pc = 12pt * /
 

In cases where the specified length cannot be supported, UAs should try to approximate. For all CSS1 properties, further computations and inheritance should be based on the approximated value.

See Also:
CssPercentage

Constructor Index

 o CssLength()
Create a new CssLength

Method Index

 o equals(Object)
Compares two values for equality.
 o get()
Returns the current value
 o getUnit()
Returns the current value
 o set(String, Frame)
Set the value of this length.
 o toString()
Returns a string representation of the object.

Constructors

 o CssLength
 public CssLength()
Create a new CssLength

Methods

 o set
 public void set(String s,
                 Frame frame) throws InvalidParamException
Set the value of this length.

Parameters:
s - the string representation of the length.
frame - For errors and warnings reports.
Throws: InvalidParamException
The unit is incorrect
Overrides:
set in class CssValue
 o get
 public Object get()
Returns the current value

Overrides:
get in class CssValue
 o getUnit
 public String getUnit()
Returns the current value

 o toString
 public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
 o equals
 public boolean equals(Object value)
Compares two values for equality.

Parameters:
value - The other value.
Overrides:
equals in class CssValue

All Packages  Class Hierarchy  This Package  Previous  Next  Index