Borders
ON THIS PAGE
| Property Name | Some Possible Values | What It Does |
|---|---|---|
| border | 1px solid black | Defines all borders |
| border-top | 1px solid black | Defines top border |
| border-bottom | 1px solid black | Defines bottom border |
| border-left | 1px solid black | Defines left border |
| border-right | 1px solid black | Defines right border |
NOTES:
- Pixels (px) ~ This sets the thickness of the border in pixels. The syntax is any number followed by
px.
Example:border: 1px solid;
There are other measurements you can use to define the thickness of borders but personally I think it's best to use pixels to maintain a tight control on how your web page looks. (More about pixels...) - Border
Border-top
Border-bottom
Border-left
Border-right
These are all shorthand CSS properties, i.e., they allow you to apply several different values to a kind of 'all-purpose' property thus saving space and time.
For example, if it were written in 'longhand', you could conceivably be writing twelve different style declarations to apply width, style and color to all four borders of a block element. The following example will illustrate:
Click on the buttons above to see the difference between writing CSS longhand and CSS shorthand. Both of the above examples will produce the exact same result.
DIV {
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
border-top-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-right-style: solid;
border-top-color: black;
border-bottom-color: black;
border-left-color: black;
border-right-color: black;
}
DIV {
border: 1px solid black;
}
Using the propertiesborderandborder-topas examples, the shorthand syntax is written as follows:
border: width style color;
border-top: width style color;
OR just simply...
border: width style;
border-top: width style;
In the above:
width= Any CSS measurement but it's easiest to use pixels - e.g.,1pxstyle= Any one of the following:
none- No border. Same as setting the border-width to 0px.dotted- The border is drawn as a series of dots.dashed- The border is drawn as a series of dashes.solid- The border is drawn as a solid line.double- The border is drawn as two solid lines.groove- The border appears carved into the canvas.ridge- The opposite of 'groove': the border appears as though it were coming out of the canvas.inset- The border is drawn to apply a 3D inset appearance to the block element.outset- The opposite of 'inset': The border is drawn to apply a 3D outset appearance to the block element.
(NOTE: When
styleis omitted, the border style defaults tonone. Hence if you want to actually create a border, it is necessary to declarestyle[andwidthif you don't want to use browser defaults (usually around 2 pixels)]. Values declaringcolormay be omitted.)color= Any named color or hexadecimal color code, e.g.,red,green,blue,#ffffcc, etc. (Please see font color for more about what colors you can use for any HTML or CSS code.)(NOTE: When
coloris omitted, the border is rendered in the same color as the element's defined or inherited color. (See Font Styles properties for more information about thecolorproperty.)
Here's an example of an inline style applied to a paragraph tag using some of the CSS properties described in the table above:
<p style="border: 3px double red;">How now brown cow</p>
OR...
The same thing could be declared as an embedded stylesheet in the document head:
<style type="text/css">
<!--
p {
border: 3px double red;
}
-->
</style>
...and in the document body, you would simply put this:
<p>How now brown cow</p>
Both Example 1 and Example 2 will produce the following effect:
How now brown cow
And to complement your ability to draw borders on block elements, you'll want to learn how to apply backgrounds...
MORE CSS PROPERTIES:
SEE ALSO:
- How to Use CSS - An Overview
- Inline Styles
- Embedded Style Sheets
- External Style Sheets
- Class Selectors
| <~ BACK | TOP | NEXT ~> |
