user1679941
user1679941

Reputation:

Can I combine CSS for border width and color into one?

I would like to specify a top border with a width of 1px that is red. I was trying like this and it seems to work:

border-width: 1px 0px 0px;
border: 1px solid #ff0000;

However is there a way I can do this with just the one CSS statement and combine these two?

Note that I need to override a previous setting of border width so I can't just use border-top :-(

Upvotes: 0

Views: 1138

Answers (2)

MarcinJuraszek
MarcinJuraszek

Reputation: 125640

According to CSS3 specification:

The ‘border’ property is a shorthand property for setting the same width, color, and style for all four borders of a box. Unlike the shorthand ‘margin’ and ‘padding’ properties, the ‘border’ property cannot set different values on the four borders. To do so, one or more of the other border properties must be used.

However, on your situation setting just border-top would left other borders on default, which is none.

Upvotes: 1

Andy
Andy

Reputation: 14575

This should work:

border-top: 1px solid #f00;

Upvotes: 1

Related Questions