简体   繁体   中英

Borders applying font color in CSS

As CSS beginner I noticed that if you do not declare border color in a shorthand form, but before that you declare font color, that color will apply to the former as well eg

#crazyElement {color:red; border:1px solid;}

both will be red. Moreover, if you declare font color for the body, each border without declared color in shorthand form will apply that color also.

Is this normal? Maybe it's nothing special, but as a novice I just wanted to check...

That is normal, and perfectly inline with the specification

If an element's border color is not specified with a border property, user agents must use the value of the element's 'color' property as the computed value for the border color.

via @BoltClock CSS3 Spec. and the currentColor which is how it is defined.

From the specs :

This property describes the foreground color of an element's text content. In addition it is used to provide a potential indirect value (currentColor) for any other properties that accept color values. If the 'currentColor' keyword is set on the 'color' property itself, it is treated as 'color: inherit'.

So yes, it's normal.

Certain properties in CSS are automatically inherited.

Here's the list: http://www.w3.org/TR/CSS21/propidx.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM