Gradient borders

后端 未结 17 1456
一个人的身影
一个人的身影 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:42

    There is a nice css tricks article about this here: https://css-tricks.com/gradient-borders-in-css/

    I was able to come up with a pretty simple, single element, solution to this using multiple backgrounds and the background-origin property.

    .wrapper {
      background: linear-gradient(#222, #222), 
                  linear-gradient(to right, red, purple);
      background-origin: padding-box, border-box;
      background-repeat: no-repeat; /* this is important */
      border: 5px solid transparent;
    }
    

    The nice things about this approach are:

    1. It isn’t affected by z-index
    2. It can scale easily by just changing the width of the transparent border

    Check it out: https://codepen.io/AlexOverbeck/pen/axGQyv?editors=1100

提交回复
热议问题