Thursday, December 29, 2011

CSS: Numbers: Integers

By Richard York

CSS allows numbers as values for several properties. Two types of numbers are accepted by CSS: integers and real numbers. Like strings, integers and real numbers are data types and are often used in CSS for the measurement of length. The first type, integer, is expected to be exclusively a whole number, meaning no decimals are allowed.


In CSS, an integer may be preceded by a plus (+) or minus (-) to indicate the sign. Although some properties do not accept negative values, many do. As you can see in the following example, one property that allows negative values is the margin property.
Try It Out-Setting a Negative Margin
Enter the following markup:
Example 2-8. To see what happens when the margin property has a negative value, follow these steps.
  1. Save the markup that you entered as Example_2-8.html, and load it into your favorite browser. You should see something like what you see in Figure 2-23.

    Figure 2-23

How It Works
From Figure 2-23, you can see that the position of the
element has been altered by the addition of the negative margin. It has been moved a little off-screen on the left and just a tad off-screen on the top.
Post a Comment