Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS border-image gradient on one side?

Tags:

css

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?

like image 892
iRyanBell Avatar asked Jul 22 '15 16:07

iRyanBell


People also ask

How do you color a half border in CSS?

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.

Can Borders have gradients CSS?

Gradient borders are not directly supported by using CSS.

How do you add a gradient to a border in 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.

What is radial gradient in CSS?

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).


2 Answers

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>
like image 174
Etheryte Avatar answered Sep 30 '22 11:09

Etheryte


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%;
}
like image 39
Rajitha Kilaru Avatar answered Sep 30 '22 12:09

Rajitha Kilaru