I'm trying to apply a gradient to a border, I thought it was as simple as doing this:
border-color: -moz-linear-gradient(top, #555555, #111111);
But this does not work.
Does anyone know what is the correct way to do border gradients?
I'm trying to apply a gradient to a border, I thought it was as simple as doing this:
border-color: -moz-linear-gradient(top, #555555, #111111);
But this does not work.
Does anyone know what is the correct way to do border gradients?
border-image-slice
will extend a CSS border-image gradientThis (as I understand it) prevents the default slicing of the "image" into sections - without it, nothing appears if the border is on one side only, and if it's around the entire element four tiny gradients appear in each corner.
For cross-browser support you can try as well imitate a gradient border with
:before
or:after
pseudo elements, depends on what you want to do.Another hack for achieving the same effect is to utilize multiple background images, a feature that is supported in IE9+, newish Firefox, and most WebKit-based browsers: http://caniuse.com/#feat=multibackgrounds
There are also some options for using multiple backgrounds in IE6-8: http://www.beyondhyper.com/css3-multiple-backgrounds-in-non-supportive-browsers/
For example, suppose you want a 5px-wide left border that is a linear gradient from blue to white. Create the gradient as an image and export to a PNG. List any other CSS backgrounds after the one for the left border gradient:
You can adapt this technique to top, right, and bottom border gradients by changing the background position part of the
background
shorthand property.Here is a jsFiddle for the given example: http://jsfiddle.net/jLnDt/
— https://developer.mozilla.org/en/CSS/-moz-linear-gradient
— http://www.cssportal.com/css3-preview/borders.htm
It's a hack, but you can achieve this effect in some cases by using the background-image to specify the gradient and then masking the actual background with a box-shadow. For example:
From: http://blog.nateps.com/the-elusive-css-border-gradient
I agree with szajmon. The only problem with his and Quentin's answers is cross-browser compatibility.
HTML:
CSS: