CSS Border (Cont.)


Border Width
The border-width property is used to set the width of the border. The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or thick. The border-width property does not work if it is used alone. Use the border-style property to set the borders first.
   p.one { border-style:solid;  border-width:5px; }
   p.two { border-style:solid;  border-width:medium; }
Border Color
The border-color property is used to set the color of the border. The color can be set by name, RGB, or hex. You can also set the border color to transparent. The border-color property does not work if it is used alone. Use the border-style property to set the borders first.
   p.one { border-style:solid;  border-color:red; }
   p.two { border-style:solid;  border-color:#98bf21; }
Border—Shorthand Property
As you can see from the examples above, there are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the border properties in one property. This is called a shorthand property. The shorthand property for the border properties is border:
   border:5px solid red;
When using the border property, the order of the values are: It does not matter if one of the values above are missing (although, border-style is required), as long as the rest are in the specified order.

All CSS Border Properties
The number in the “CSS” column indicates in which CSS version the property is defined (CSS1 or CSS2).

Property Description Values CSS
border A shorthand property for setting all of the properties for the four borders in one declaration border-width
border-style
border-color
1
border-bottom A shorthand property for setting all of the properties for the bottom border in one declaration border-bottom-width
border-style
border-color
1
border-bottom-color Sets the color of the bottom border border-color 2
border-bottom-style Sets the style of the bottom border border-style 2
border-bottom-width Sets the width of the bottom border thin
medium
thick
length
1
border-color Sets the color of the four borders, can have from one to four colors color 1
border-left A shorthand property for setting all of the properties for the left border in one declaration border-left-width
border-style
border-color
1
border-left-color Sets the color of the left border border-color 2
border-left-style Sets the style of the left border border-style 2
border-left-width Sets the width of the left border thin
medium
thick
length
1
border-right A shorthand property for setting all of the properties for the right border in one declaration border-right-width
border-style
border-color
1
border-right-color Sets the color of the right border border-color 2
border-right-style Sets the style of the right border border-style 2
border-right-width Sets the width of the right border thin
medium
thick
length
1
border-style Sets the style of the four borders, can have from one to four styles none
hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
1
border-top A shorthand property for setting all of the properties for the top border in one declaration border-top-width
border-style
border-color
1
border-top-color Sets the color of the top border border-color 2
border-top-style Sets the style of the top border border-style 2
border-top-width Sets the width of the top border thin
medium
thick
length
1
border-width A shorthand property for setting the width of the four borders in one declaration, can have from one to four values thin
medium
thick
length
1


Demonstration
The following demonstration shows how the script of HTML and CSS is displayed on the Web: