Gradient borders

后端 未结 17 1443
一个人的身影
一个人的身影 2020-11-22 03:40

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


        
17条回答
  •  花落未央
    2020-11-22 04:22

    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:

    #theBox {
        background:
            url(/images/theBox-leftBorderGradient.png) left no-repeat,
            ...;
    }
    

    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/

提交回复
热议问题