|
CSS1 Properties
Syntax Used in Property Definitions
Font PropertiesFont Family
Font families may be assigned by a specific font name or a generic font family. Obviously, defining a specific font will not be as likely to match as a generic font family. Multiple family assignments can be made, and if a specific font assignment is made it should be followed by a generic family name in case the first choice is not present. A sample font-family declaration might look like this:
Notice that the first two assignments are specific type faces: New Century Schoolbook and Times. However, since both of them are serif fonts, the generic font family is listed as a backup in case the system does not have either of these but has another serif font which meets the qualifications. Any font name containing whitespace must be quoted, with either single or double quotes. The font family may also be given with the font property. Font Style
The font-style property defines that the font be displayed in one of three ways: normal, italic or oblique (slanted). A sample style sheet with font-style declarations might look like this:
Font Variant
The font-variant property determines if the font is to display in normal or small-caps. Small-caps are displayed when all the letters of the word are in capitals with uppercase characters slightly larger than lowercase. Later versions of CSS may support additional variants such as condensed, expanded, small-caps numerals or other custom variants. An example of a font-variant assignment would be:
Font Weight
The font-weight property is used to specify the weight of the font. The bolder and lighter values are relative to the inherited font weight, while the other values are absolute font weights. Note: Since not all fonts have nine possible display weights some of the weights may be grouped together in assignment. If the specified weight is not available, an alternate will be chosen on the following basis:
Some example font-weight assignments would be:
Font Size
The font-size property is used to modify the size of the displayed font. Absolute lengths (using units like pt and in) should be used sparingly due to their weakness in adapting to different browsing environments. Fonts with absolute lengths can very easily be too small or too large for a user. Some example size assignments would be:
Authors should be aware that Microsoft Internet Explorer 3.x incorrectly treats em and ex units as pixels, which can easily make text using these units unreadable. The browser also incorrectly applies percentage values relative to its default font size for the selector, rather than relative to the parent element's font size. This makes rules like
dangerous in that the size will be twice IE's default font size for level-one headings, rather than twice the parent element's font size. In this case, BODY would most likely be the parent element, and it would likely define a medium font size, whereas the default level-one heading font size imposed by IE would probably be considered xx-large. Given these bugs, authors should take care in using percentage values for font-size, and should probably avoid em and ex units for this property. Font
The font property may be used as a shorthand for the various font properties, as well as the line height. For example,
specifies paragraphs with a bold and italic Times or serif font with a size of 12 points and a line height of 14 points. Color and Background Properties
Color
The color property allows authors to specify the color of an element. See the Units section for color value descriptions. Some example color rules include:
To help avoid conflicts with user style sheets, background and color properties should always be specified together. Background Color
The background-color property sets the background color of an element. For example:
To help avoid conflicts with user style sheets, background-image should be specified whenever background-color is used. In most cases, background-image: none is suitable. Authors may also use the shorthand background property, which is currently better supported than the background-color property. Background Image
The background-image property sets the background image of an element. For example:
When a background image is defined, a similar background color should also be defined for those not loading images. Authors may also use the shorthand background property, which is currently better supported than the background-image property. Background Repeat
The background-repeat property determines how a specified background image is repeated. The repeat-x value will repeat the image horizontally while the repeat-y value will repeat the image vertically. For example:
In the above example, the image will only be tiled horizontally. Authors may also use the shorthand background property, which is currently better supported than the background-repeat property. Background Attachment
The background-attachment property determines if a specified background image will scroll with the content or be fixed with regard to the canvas. For example, the following specifies a fixed background image:
Authors may also use the shorthand background property, which is currently better supported than the background-attachment property. Background Position
The background-position property gives the initial position of a specified background image. This property may only be applied to block-level elements and replaced elements. (A replaced element is one for which only the intrinsic dimensions are known; HTML replaced elements include IMG, INPUT, TEXTAREA, SELECT, and OBJECT.) The easiest way to assign a background position is with keywords:
Percentages and lengths may also be used to assign the position of the background image. Percentages are relative to the size of the element. Although lengths are allowed, they are not recommended due to their inherent weakness in dealing with differing display resolutions. When using percentages or lengths, the horizontal position is specified first, followed by the vertical position. A value such as 20% 65% specifies that the point 20% across and 65% down the image be placed at the point 20% across and 65% down the element. A value such as 5px 10px specifies that the upper left corner of the image be placed 5 pixels to the right of and 10 pixels below the upper left corner of the element. If only the horizontal value is given, the vertical position will be 50%. Combinations of lengths and percentages are allowed, as are negative positions. For example, 10% -2cm is permitted. However, percentages and lengths cannot be combined with keywords. The keywords are interpreted as follows:
If the background image is fixed with regard to the canvas, the image is placed relative to the canvas instead of the element. Authors may also use the shorthand background property, which is currently better supported than the background-position property. Background
The background property is a shorthand for the more specific background-related properties. Some examples of background declarations follow:
A value not specified will receive its initial value. For example, in the first three rules above, the background-position property will be set to 0% 0%. To help avoid conflicts with user style sheets, background and color properties should always be specified together. Text Properties
Word Spacing
The word-spacing property defines an additional amount of space between words. The value must be in the length format; negative values are permitted. Examples:
Letter Spacing
The letter-spacing property defines an additional amount of space between characters. The value must be in the length format; negative values are permitted. A setting of 0 will prevent justification. Examples:
Text Decoration
The text-decoration property allows text to be decorated through one of five properties: underline, overline, line-through, blink, or the default, none. For example, one can suggest that links not be underlined with
Vertical Alignment
The vertical-align property may be used to alter the vertical positioning of an inline element, relative to its parent element or to the element's line. (An inline element is one which has no line break before and after it, for example, EM, A, and IMG in HTML.) The value may be a percentage relative to the element's line-height property, which would raise the element's baseline the specified amount above the parent's baseline. Negative values are permitted. The value may also be a keyword. The following keywords affect the positioning relative to the parent element:
The keywords affecting the positioning relative to the element's line are
The vertical-align property is particularly useful for aligning images. Some examples follow:
Text Transformation
The text-transform property allows text to be transformed by one of four properties:
Examples:
The text-transform property should only be used to express a stylistic desire. It would be inappropriate, for example, to use text-transform to capitalize a list of countries or names. Text Alignment
The text-align property can be applied to block-level elements (P, H1, etc.) to give the alignment of the element's text. This property is similar in function to HTML's ALIGN attribute on paragraphs, headings, and divisions. Some examples follow:
Text Indentation
The text-indent property can be applied to block-level elements (P, H1, etc.) to define the amount of indentation that the first line of the element should receive. The value must be a length or a percentage; percentages refer to the parent element's width. A common use of text-indent would be to indent a paragraph:
Line Height
The line-height property will accept a value to control the spacing between baselines of text. When the value is a number, the line height is calculated by multiplying the element's font size by the number. Percentage values are relative to the element's font size. Negative values are not permitted. Line height may also be given in the font property along with a font size. The line-height property could be used to double space text:
Microsoft Internet Explorer 3.x incorrectly treats number values and values with em or ex units as pixel values. This bug can easily make pages unreadable, and so authors should avoid provoking it wherever possible; percentage units are often a good choice. Box Properties
Top Margin
The margin-top property sets the top margin of an element by specifying a length or a percentage. Percentage values refer to the parent element's width. Negative margins are permitted. For example, the following rule would eliminate the top margin of a document:
Note that adjoining vertical margins are collapsed to use the maximum of the margin values. Right Margin
The margin-right property sets the right margin of an element by specifying a length or a percentage. Percentage values refer to the parent element's width. Negative margins are permitted. Example:
Note that adjoining horizontal margins are not collapsed. Bottom Margin
The margin-bottom property sets the bottom margin of an element by specifying a length or a percentage. Percentage values refer to the parent element's width. Negative margins are permitted. Example:
Note that adjoining vertical margins are collapsed to use the maximum of the margin values. Left Margin
The margin-left property sets the left margin of an element by specifying a length or a percentage. Percentage values refer to the parent element's width. Negative margins are permitted. Example:
Note that adjoining horizontal margins are not collapsed. Margin
The margin property sets the margins of an element by specifying between one and four values, where each value is a length, a percentage, or auto. Percentage values refer to the parent element's width. Negative margins are permitted. If four values are given, they apply to top, right, bottom, and left margin, respectively. If one value is given, it applies to all sides. If two or three values are given, the missing values are taken from the opposite side. Examples of margin declarations include:
Note that adjoining vertical margins are collapsed to use the maximum of the margin values. Horizontal margins are not collapsed. Using the margin property allows one to set all margins; alternatively, the properties margin-top, margin-bottom, margin-left, and margin-right may be used. Top Padding
The padding-top property describes how much space to put between the top border and the content of the selector. The value is either a length or a percentage. Percentage values refer to the parent element's width. Negative values are not permitted. Right Padding
The padding-right property describes how much space to put between the right border and the content of the selector. The value is either a length or a percentage. Percentage values refer to the parent element's width. Negative values are not permitted. Bottom Padding
The padding-bottom property describes how much space to put between the bottom border and the content of the selector. The value is either a length or a percentage. Percentage values refer to the parent element's width. Negative values are not permitted. Left Padding
The padding-left property describes how much space to put between the left border and the content of the selector. The value is either a length or a percentage. Percentage values refer to the parent element's width. Negative values are not permitted. Padding
The padding property is a shorthand for the padding-top, padding-right, padding-bottom, and padding-left properties. An element's padding is the amount of space between the border and the content of the element. Between one and four values are given, where each value is either a length or a percentage. Percentage values refer to the parent element's width. Negative values are not permitted. If four values are given, they apply to top, right, bottom, and left padding, respectively. If one value is given, it applies to all sides. If two or three values are given, the missing values are taken from the opposite side. For example, the following rule sets the top padding to 2em, the right padding to 4em, the bottom padding to 5em, and the left padding to 4em:
Top Border Width
The border-top-width property is used to specify the width of an element's top border. The value may be one of three keywords, which are not affected by font size, or a length, which can be used to achieve relative widths. Negative values are not allowed. One may also use the border-top, border-width, or border shorthand properties. Right Border Width
The border-right-width property is used to specify the width of an element's right border. The value may be one of three keywords, which are not affected by font size, or a length, which can be used to achieve relative widths. Negative values are not allowed. One may also use the border-right, border-width, or border shorthand properties. Bottom Border Width
The border-bottom-width property is used to specify the width of an element's bottom border. The value may be one of three keywords, which are not affected by font size, or a length, which can be used to achieve relative widths. Negative values are not allowed. One may also use the border-bottom, border-width, or border shorthand properties. Left Border Width
The border-left-width property is used to specify the width of an element's left border. The value may be one of three keywords, which are not affected by font size, or a length, which can be used to achieve relative widths. Negative values are not allowed. One may also use the border-left, border-width, or border shorthand properties. Border Width
The border-width property is used to set the border width of an element by specifying between one and four values, where each value is a keyword or a length. Negative lengths are not permitted. If four values are given, they apply to top, right, bottom, and left border width, respectively. If one value is given, it applies to all sides. If two or three values are given, the missing values are taken from the opposite side. This property is a shorthand for the border-top-width, border-right-width, border-bottom-width, and border-left-width properties. One may also use the border shorthand property. Border Color
The border-color property sets the color of an element's border. Between one and four color values are specified. If four values are given, they apply to top, right, bottom, and left border color, respectively. If one value is given, it applies to all sides. If two or three values are given, the missing values are taken from the opposite side. One may also use the border shorthand property. Border Style
The border-style property sets the style of an element's border. This property must be specified for the border to be visible. Between one and four keywords are specified. If four values are given, they apply to top, right, bottom, and left border style, respectively. If one value is given, it applies to all sides. If two or three values are given, the missing values are taken from the opposite side. One may also use the border shorthand property. Top Border
The border-top property is a shorthand for setting the width, style, and color of an element's top border. Note that only one border-style value may be given. One may also use the border shorthand property. Right Border
The border-right property is a shorthand for setting the width, style, and color of an element's right border. Note that only one border-style value may be given. One may also use the border shorthand property. Bottom Border
The border-bottom property is a shorthand for setting the width, style, and color of an element's bottom border. Note that only one border-style value may be given. One may also use the border shorthand property. Left Border
The border-left property is a shorthand for setting the width, style, and color of an element's left border. Note that only one border-style value may be given. One may also use the border shorthand property. Border
The border property is a shorthand for setting the width, style, and color of an element's border. Examples of border declarations include:
The border property can only set all four borders; only one border width and border style may be given. To give different values to an element's four borders, an author must use one or more of the border-top, border-right, border-bottom, border-left, border-color, border-width, border-style, border-top-width, border-right-width, border-bottom-width, or border-left-width properties. Width
Each block-level or replaced element can be given a width, specified as a length, a percentage, or as auto. (A replaced element is one for which only the intrinsic dimensions are known; HTML replaced elements include IMG, INPUT, TEXTAREA, SELECT, and OBJECT.) The initial value for the width property is auto, which results in the element's intrinsic width (i.e., the width of the element itself, for example the width of an image). Percentages refer to the parent element's width. Negative values are not allowed. This property could be used to give common widths to some INPUT elements, such as submit and reset buttons:
Height
Each block-level or replaced element can be given a height, specified as a length or as auto. (A replaced element is one for which only the intrinsic dimensions are known; HTML replaced elements include IMG, INPUT, TEXTAREA, SELECT, and OBJECT.) The initial value for the height property is auto, which results in the element's intrinsic height (i.e., the height of the element itself, for example the height of an image). Negative lengths are not allowed. As with the width property, height can be used to scale an image:
In most cases, authors are advised to scale the image in an image editing program, since browsers will not likely scale images with high quality, and since scaling down causes the user to download an unnecessarily large file. However, scaling through the width and height properties is a useful option for user-defined style sheets in order to overcome vision problems. Float
The float property allows authors to wrap text around an element. This is identical in purpose to HTML 3.2's ALIGN=left and ALIGN=right for the IMG element, but CSS1 allows all elements to "float," not just the images and tables that HTML 3.2 allows. Clear
The clear property specifies if an element allows floating elements to its sides. A value of left moves the element below any floating element on its left; right acts similarly for floating elements on the right. Other values are none, which is the initial value, and both, which moves the element below floating elements on both of its sides. This property is similar in function to HTML 3.2's <BR CLEAR=left|right|all|none>, but it can be applied to all elements. Classification PropertiesDisplay
The display property is used to define an element with one of four values:
Each element typically is given a default display value by the browser, based on suggested rendering in the HTML specification. The display property can be dangerous because of its ability to display elements in what would otherwise be an improper format. The use of the value none will turn off display of the element to which it is assigned, including any children elements! Whitespace
The white-space property will determine how spaces within the element are treated. This property takes one of three values:
List Style Type
The list-style-type property specifies the type of list-item marker, and is used if list-style-image is none or if image loading is turned off. Examples:
List Style Image
The list-style-image property specifies the image that will be used as list-item marker when image loading is turned on, replacing the marker specified in the list-style-type property. Examples:
List Style Position
The list-style-position property takes the value inside or outside, with outside being the default. This property determines where the marker is placed in regard to the list item. If the value inside is used, the lines will wrap under the marker instead of being indented. An example rendering is: Outside rendering: * List item 1 second line of list item Inside rendering: * List item 1 second line of list item List Style
The list-style property is a shorthand for the list-style-type, list-style-position, and list-style-image properties. Examples:
UnitsLength UnitsA length value is formed by an optional + or -, followed by a number, followed by a two-letter abbreviation that indicates the unit. There are no spaces in a length value; e.g., 1.3 em is not a valid length value, but 1.3em is valid. A length of 0 does not require the two-letter unit identifier. Both relative and absolute length units are supported in CSS1. Relative units give a length relative to another length property, and are preferred since they will better adjust to different media. The following relative units are available:
Absolute length units are highly dependent on the output medium, and so are less useful than relative units. The following absolute units are available:
Percentage UnitsA percentage value is formed by an optional + or -, followed by a number, followed by %. There are no spaces in a percentage value. Percentage values are relative to other values, as defined for each property. Most often the percentage value is relative to the element's font size. Color UnitsA color value is a keyword or a numerical RGB specification. The 16 keywords are taken from the Windows VGA palette: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. RGB colors are given in one of four ways:
The examples above all specify the same color. Douglas R. Jacobson has also developed a handy quick reference RGB Color Chart (61 kB). URLsA URL value is given by url(foo), where foo is the URL. The URL may be optionally quoted with either single (') or double (") quotes and may contain whitespace before or after the (optionally quoted) URL. Parentheses, commas, spaces, single quotes, or double quotes in the URL must be escaped with a backslash. Partial URLs are interpreted relative to the style sheet source, not to the HTML source. Note that Netscape Navigator 4.x incorrectly interprets partial URLs relative to the HTML source. Given this bug, authors may wish to use full URLs where possible. Examples:
Maintained by John Pozadzides and Liam Quinn Copyright © 1997 John Pozadzides and Liam Quinn. All rights reserved. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
With any suggestions or questions please feel free to contact us |