CSS Lengths

Description

Many CSS properties require you to specify a length, for examples the width property, the font-size property.

Example

The following code sets Units of Measurement in Properties


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
p  {<!--   ww w.  j av a 2 s  .co m-->
    background: grey;
    color:white;
    width: 5cm;
    font-size:  20pt;
}
</style>
</head>
<body>
   <p>this is a test.</p>
</body>
</html>

Click to view the demo

To specify a length, you concatenate the number and the unit identifier together.

In the code above, width property is 5cm. The font size is 20pt.

CSS defines two kinds of length unit

  • absolute
  • relative




















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table