Style borderColor egenskap
- Föregående sida borderCollapse
- Nästa sida borderImage
- Åter till föregående nivå HTML DOM Style-objekt
Definition och användning
borderColor
Egenskapen ställer in eller returnerar elementets kantfärg.
Denna egenskap kan använda en till fyra värden:
- Ett värde, till exempel: p {border-color: red} - alla fyra kanter är röda
- Two values, for example: p {border-color: red transparent} - The top and bottom borders are red, and the left and right borders are transparent
- Three values, for example: p {border-color: red green blue} - The top border is red, the left and right borders are green, and the bottom border is blue
- Four values, for example: p {border-color: red green blue yellow} - The top border is red, the right border is green, the bottom border is blue, and the left border is yellow
See also:
CSS Tutorial:CSS-kant
CSS Reference Manual:border-color property
HTML DOM Reference Manual:border property
Example
Example 1
Change the color of all four borders of the <div> element to red:
document.getElementById("myDiv").style.borderColor = "red";
Example 2
Change the color of the top and bottom borders of the <div> element to green, and the color of the left and right borders to purple:
document.getElementById("myDiv").style.borderColor = "green purple";
Example 3
Return the border color of the <div> element:
alert(document.getElementById("myDiv").style.borderColor);
Syntax
Return borderColor property:
object.style.borderColor
Set borderColor property:
object.style.borderColor = "color|transparent|initial|inherit"
Attribute value
Value | Description |
---|---|
color |
Specify the border color. The default color is black. Please see CSS color values, for a complete list of possible color values. |
transparent | The border color is transparent (the underlying content will show through). |
initial | Set this property to its default value. See initial. |
inherit | Inherit this property from its parent element. See inherit. |
Technical details
Default value: | black |
---|---|
Return value: | A string that represents the color of the element's border. |
CSS version: | CSS1 |
Browser support
Table numbers indicate the first browser version to fully support this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
- Föregående sida borderCollapse
- Nästa sida borderImage
- Åter till föregående nivå HTML DOM Style-objekt