Shorthand for border properties?

Is it possible to reduce:

border-top:1px solid black;
border-left:2px solid red;
border-bottom:3px solid green;
border-right:4px solid blue;

Something similar to:

border:1px solid black 2px solid red 3px solid green 4px solid blue;

NB: I already know:

border-width:1px 2px 3px 4px;
border-style:solid;
border-color:black red green blue;
+5
source share
1 answer

No, you cannot make it shorter than the examples you cited.

From the documents

Unlike the abbreviated field and padding properties, the borders of a property cannot set different values ​​on four borders. To do this, you must use one or more other border properties.

Thanks @Rocket


If you use a preprocessor (like SCSS), you can try using mixin, but I hardly believe you want:

@mixin border_shorthand(
$top_width, $top_color, $top_style,
$left_width, $left_color, $left_style,
$bottom_width, $bottom_color, $bottom_style,
$right_width, $right_color, $right_style) {
  border-top: $top_width $top_color $top_style;
  border-left: $left_width $left_color $left_style;
  border-bottom: $bottom_width $bottom_color $bottom_style;
  border-right: $right_width $right_color $right_style;
}

.element {
  @include border_shorthand(1px, black, solid, 2px, red, solid, 3px, green, solid, 4px, blue, solid);
}

What outputs:

.element {
  border-top: 1px black solid;
  border-left: 2px red solid;
  border-bottom: 3px green solid;
  border-right: 4px blue solid; }
+11
source

All Articles