Reputation: 32785
Sometimes I find myself in a situation where I want to define a border
rule for the left and right side of an element. But honestly, border-left: solid 1px #999; border-right: solid 1px #999
is little clumsy. It wastes space, I have to apply changes twice and it may or may not be rendered less efficiently.
Is there a way to define horizontal borders or vertical borders in one go?
Upvotes: 1
Views: 2661
Reputation: 67204
You can do it in one go like this:
#myDiv
{
width: 100px;
height: 100px;
border: 1px solid #999;
border-width: 0 1px; /*horizontal, vertical*/
}
Upvotes: 3
Reputation: 6996
<div id="myDiv">Your Div</div>
CSS:
#myDiv
{
border-width:0 1px 0 1px;
border-color:#ddd;
}
Upvotes: 6
Reputation: 28697
No.
From https://developer.mozilla.org/en-US/docs/CSS/border:
While the border-width, border-style, and border-color properties and even the margin and padding shorthand properties accept up to four values, allowing to set different width, style or color, for the different border, this property only accepts one value for each property, leading to the same border for the four edges.
So you could switch to using separate border-width, border-style, and border-color properties, using their shorthand properties to set per-side styles - but I think you're best off as you have it.
That said, ensure that you're saving your style definition as a CSS class - that can then be re-used across elements, rather than applying these one-by-one in "style" attributes on elements throughout your page.
Upvotes: 0