border propertiesUsing cascading style sheets any element may have a border, of varying widths, colors and styles. Elements can even have every border (top, left, bottom, right) a different style, width and color. The border properties are:
Borders really are simple, but more than any other set of properties, they have numerous shorthand ways of setting values, which can at first appear to make them quite complicated. For this reason we've written Unscrambling the border mess below, to help you get started with an easy to understand way of creating borders. Another result of the numerous shorthands is that the exact nature of the browser support for the different properties is difficult to express in one single place. Each of the properties has the usual information about how well they are supported individually. As well, though, we have some general information at the bottom of the page which clarifies (hopefully!) some of the more tricky issues involved in making borders actually work. Unscrambling the border messAs we've just seen, and a glance at the list of border properties will demonstrate, there is an almost bewildering array of border properties, many of which are shorthand ways of saying the same thing. For example, to give the top border a width, you could use any of As a general rule, you can do everything there is to do with border properties using the following straightforward approach. To define the same border properties for each side of the element, use the border property. For example, to give each side of an element the same thin, red solid border, we'd use the following declaration {border: thin red solid} To define a border property for a given side of an element, use the border-* property. For example, to give the top edge of an element a thin, red solid border, and the bottom edge a thick black dotted border we'd use the following declaration {border-top: thin red solid; border-bottom: thick black dotted} It really is that simple. See below for details of what values you can give a border for its For completeness, we discuss each of the possible properties and shorthands in turn. border-top-width, border-left-width, border-bottom-width, border-right-width, border-widthWhat it doesThese properties let you set the width of the respective edges individually or all at once. Possible valuesBorder widths can take either keyword values, or length values. The keyword values that can be used are
There is no precise specification for how these keywords should be drawn, so different browsers will probably (and as of writing indeed do) draw them as different thicknesses. The only guarantee is that Length values are discussed in detail in our section on values. Using relative length values you can create borders that are in proportion with the size of an element, or its contents. Default valuesIf no width is set, the thickness of a border is Is it inherited?An element does not inherit the thickness of its parent element's border. Hints and suggestionsThe
Browser supportDetailed browser support information for this feature can be found in the full version of the Westciv CSS Guide, or in our CSS Browser Support Table. border-colorWhat it doesUnlike border widths which we have just seen, Possible values
You can use
Default valuesIf no color is specified for the border, the border has the same value as the element itself, that is the value specified by the Is it inherited?The Hints and suggestionsAs with border widths (and all border properties) support for different edges is far from perfect in Netscape prior to version 6. Browser supportDetailed browser support information for this feature can be found in the full version of the Westciv CSS Guide, or in our CSS Browser Support Table. border-styleWhat it doesIn addition to width and color, the border of an element, or its individual edges can have a style.
There are several possible styles, though not all are currently supported by major browsers. Possible valuesAs with You can use border-style to give different styles to each edge of an element.
The
Rather than describe them, investigate each by way of example. You'll find that many appear the same in most browsers, because support for this property is not yet 100%. Default valuesIf no Is it inherited?Elements do not inherit the Hints and suggestionsAs with other border properties, support for specifying different edges of a border is far from perfect in major browsers. You should also keep in mind that some browsers do not support every kind of style. Usually, where a style keyword is not supported, the browser draws the border as Browser supportDetailed browser support information for this feature can be found in the full version of the Westciv CSS Guide, or in our CSS Browser Support Table. border-top, border-left, border-bottom, border-right, borderWhat it doesAs mentioned at the beginning of this section, there are confusingly many, and inconsistently different shorthand ways of specifying border values. These five properties let you specify with one property any or all of the Possible valuesThe shorthand properties simply take the same possible values as the full properties. As with the long hand way of describing borders, if you only give a value for style the border will be drawn with a default width and color. To specify more than one property value with a shorthand property, simply separate the values by a space. For example, to specify the color, width and style of the top edge of a border of an element you could use the following single property
Default valuesThe default values of each type of property are discussed in the relevant sections above. Is it inherited?None of the border values of a parent element are inherited by child elements. Hints and suggestionsKeep in mind that not all styles are supported by each browser, nor do all browsers fully support different values on different edges of each border. Browser supportDetailed browser support information for this feature can be found in the full version of the Westciv CSS Guide, or in our CSS Browser Support Table. next: margin properties
|