The values that can be applied to the various CSS properties fall into five categories; keyword, length, percentage, color and URL.
There are a couple of rules which can cause problems if not followed. For values that use units, there must not be a space between the value and the unit. Unlike attribute values for HTML elements, values should not be in quotes (" ..") except for string values and those font names (e.g."Times New Roman")which contain whitespace in their name.
font-size: 1.5 em; /* invalid */ font-size: 1.5em; /* valid */ border: 1px "solid"; /* invalid */ border: 1px solid; /* valid */
Technically font names without whitespace can be quoted, but it is not recommended as it may confuse some browsers.
TopThese are pre-defined explicit values.
font-weight: bold; border-top-style: solid;Top
Length values can be expressed in both absolute and relative units.
Absolute units are: in(inches); cm(centimetres); mm(millimetres); pt(points); and pc(picas).
Relative units are: em(em-height); and ex(ex-height) and px(pixels).
Although a pixel may seem to be an absolute value, it is officially defined as a relative measurement because it is relative to the display medium.
Anyway that's all by the by as it makes no difference as to how the values are specified.
A health warning needs to be issued with many of these, particularly the absolute values, as 'real-world' measurements do not always translate well to a display environment. The concept of using inches and centimetres with different screen resolutions does not really make sense. These values should only appear in a style sheet used for printing. Consequently, as I'm only covering the visual aspects, I will concentrate on the relative values (pixels included!).
Even the use of pt, which is the unit used in most word processing applications, is not advisable.
This is because the mapping of points to pixels can vary between different systems.
px is the most common unit used on the web but even that can cause problems depending on screen resolution.
Nevertheless it is popular and does give a fine degree of accuracy when absolute positioning is required.
The CSS defined pixel size is 90 pixels to the inch, but browsers as always will probably ignore this and make their own judgement.
padding-left: 5px; padding-left: 15px; padding-left: 50px;
The other one commonly used is em.
This is a relative unit based on the height of a capital "M" character which is 1em.
The height of the "M" is itself variable as it depends on the context in which is it is being used.
This can be demonstrated very well when being used to specify font-sizes.
A value of 2em will increase the font size by 100%.
However, as mentioned above, this value is relative to the default or inherited size of the element or block it is being applied to.
If the size has already been changed from it's default size, then the em length will be applied to the changed size, not the default size.
The value can be expressed as a decimal to give a greater degree of control.
font-size: not specified, inherits value from parent font-size: 1em; font-size: 1.5em; font-size: 2em; font-size: 1em;
In the example above, the application of each value is based on the size of the previous line.
As you can see, applying a length of 1em (line 2) leaves the size at its inherited value.
In the last line, a value of 1em is being applied again, but this time, to text already set to 2em.
Consequently it remains as large typeface and does not revert to the inherited value shown in the first line.
Percentages are useful in maintaining a proportional look to a web page. Again the resultant size is relative to its container. When a browser window is resized, objects defined as a percentage will resize themselves accordingly, relative to the size of the containing object.
For example, a three-column table is defined as having a width of 100% and the columns are defined as 20%, 30% and 50%.
If the size if the browser window dictates that the the table width is say, 500px, then the widths of the columns will be 100px, 150px and 250px respectively.
If the window width is reduced by half, the column widths will then be 50px, 75px and 125px respectively.
A percentage value is specified as a positive or a negative number followed by a percent sign.
width: 20%;Top
Colour values can be specified in a number of ways.
The simplest is by using one of the standard 16 keywords defined in CSS. These are based on the original Windows VGA colours. They are: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white and yellow. Other colour names have been defined, for example: BlanchedAlmond, LightGoldenRodYellow, but they are dependent on the level of support from your browser.
The other methods involve representing the levels of the base screen colors, red, green and blue. This can be done in one of four ways:
Specifying the hexadecimal value of each base color, each colour being represented by a pair of hexadecimal characters (#rrggbb).
color: #FF0000; This text is all redcolor: #BBBBBB; This text is a very light gray colorcolor: #808080; This text is a medium graycolor: #FFFFFF; It doesn't come any cleaner than thiscolor: #000000; This is as black as it getsSpecifying the short form of the hexadecimal notation of each base color (#rgb). If both hexadecimal characters for a colour are the same then they can be represented by the single character.
color: #F00; This text is all redcolor: #BBB; This text is a very light gray colorcolor: #777; This is an approximation as #808080 cannot be represented in the short formcolor: #FFF; It doesn't come any cleaner than thiscolor: #000; This is as black as it getsSpecifying the decimal equivalent of the hexadecimal value.
color: rgb(255,0,0); This text is all redcolor: rgb(187,187,187); This text is a very light gray colorcolor: rgb(128,128,128); This text is a medium graycolor: rgb(255,255,255); It doesn't come any cleaner than thiscolor: rgb(0,0,0); This is as black as it getsSpecifying the %ages of each of the base colours.
color: rgb(100%,0%,0%); This text is all redcolor: rgb(75%,75%,75%); This text is a very light gray colorcolor: rgb(50%,50%,50%); This text is a medium graycolor: rgb(100%,100%,100%); It doesn't come any cleaner than thiscolor: rgb(0%,0%,0%); This is as black as it getsA URL (Uniform Resource Locator) is the address of a resource on the Web. This, combined with a URN (Uniform Resource Name),which is a way of identifying resources on the Web, has given rise to a new term, URI (Uniform Resource Identifier).
It is this URI that is part of the CSS specification.
To all intents and purposes though, it is the normal form of a URL that is specified.
In fact the keyword used in expressing a URI value is url.
background-image: url("http://www.pretty-backgrounds.co.uk/skybluepinkwithyellowdots.gif");
URLs can be specified as an absolute or a relative value. The CSS specification says that relative values are in relation to the style sheet itself. This means that if it is an external style sheet, the value is relative to the location of the style sheet, but if it is an embedded style sheet, it is relative to the location of the document itself. However, Netscape 4 always interprets the location as relative to the document so beware of older browsers. Yet another reason to use a standards-compliant browser like Firefox!
Top