Why is “border-color” overridden by “color”?

前端 未结 6 795
野趣味
野趣味 2021-01-22 09:06

I have the following css:

.isActiveFilter {
  color: black;
  background-color: rgba(0, 184, 170, .5);
  padding: 15px 10px 10px 10px;
  border-color: red;
  bor         


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 09:20

    Why is “border-color” overridden by “color”? .... border color renders as black, not red as I would expect, as border-color is set after color. Thoughts?

    Your problem lies within how you've declared your border- properties:

    border-color: red;  /* sets the border color to red */
    border: 3px solid;  /* sets the border color to default (black) */
    

    You're using the shorthand for all border properties using border, and since you didn't specify any color within border, it's set to the default color, which is black in this case, as defined by the color property1. And since you're declaring border after border-color, you're over-riding red with black.

    Simply remove border-color and specify any border color within the border property...

    border-color: red;      /* <-- REMOVE THIS LINE */
    border: 3px solid red;  /* set the border color here */
    

    1 "A denoting the color of the border. If not set, its default value is the value of the element's color property (the text color, not the background color)."

提交回复
热议问题