Weird gradient border effect

前端 未结 7 533
旧时难觅i
旧时难觅i 2020-11-30 05:33

When applying a transparent border over an element with a linear-gradient as the background, I get a weird effect.

7条回答
  •  执念已碎
    2020-11-30 05:49

    That's because the starting and ending points of the gradient are at the edges of the padding-box and border is rendered outside the padding-box. So, the borders look funny because the background is repeated on each side outside the padding-box to cover the border-box.

    The box-shadow:inset is rendered inside the padding-box (just like background) and gives visually the same effect as a border, so you could try using that in place of border:

    box-shadow: inset 0 0 0 10px rgba(0,0,0,0.2);
    padding: 10px;
    

    Because a box-shadow doesn't take up any space, you need to increase your padding accordingly.

    Illustration of padding-box and border-box: enter image description here

    Demo http://jsfiddle.net/ilpo/fzndodgx/5/

提交回复
热议问题