The following CSS produces a gradient border on the left & right side of an element:
div {
width: 100px;
height: 100px;
border-left: 10px solid;
border-image: linear-gradient(#00f,#000) 0 100%;
}
<div></div>
http://jsfiddle.net/5p8cv5t9/
How can I apply the gradient only to the left side?
Use two gradients: one rotated 90deg and the other rotated -90deg. Use two color stops: #880015 at 50% and #fff at 50% Use a background-size of 100% width and 3px in height, i.e. background-size: 100% 3px. Position the two backgrounds at the top left and bottom left of your element.
Gradient borders are not directly supported by using CSS.
To show gradients for a border with CSS you can use the border-image property. It allows setting gradient values in the same way as the background-image property. Besides the border-image property, you should specify additional properties to actually show border gradient.
A radial gradient is defined by a center point, an ending shape, and two or more color-stop points. To create a smooth gradient, the radial-gradient() function draws a series of concentric shapes radiating out from the center to the ending shape (and potentially beyond).
You can define no border width on all other sides easily. The issue stems from the fact that the default border-width (MDN) value is medium
, not 0
.
div {
width: 100px;
height: 100px;
border-width: 0;
border-left: 10px solid;
border-image: linear-gradient(#00f, #000) 0 100%;
}
<div></div>
you can define right border to 0px. Hope this helps.
div {
width: 100px;
height: 100px;
border-left: 10px solid;
border-right: 0px;
border-image: linear-gradient(#00f,#000) 0 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With