边框左图像和边框右图像上的CSS边框图像渐变与边框颜色混合

时间:2016-03-10 21:48:23

标签: css css3 border-image css-gradients

border-top-color#9b9c9dborder-bottom-color#f6f9fc。渐变意图将顶部颜色转换为border-leftborder-right上的底部颜色。

如何将border-left-imageborder-right-imageborder-top-colorborder-bottom-color混合?

HTML

<a class="button-style">Evil Whales</a>

CSS

.button-style
{
 background: linear-gradient(to bottom,
   rgba(129,232,117,1) 0%,
   rgba(129,232,117,1) 50%,
   rgba(62,179,48,1) 51%,
   rgba(62,179,48,1) 100%);

 border-top-color: #9b9c9d;

 border-left-image: linear-gradient(to bottom,
   rgba(155,156,157,1) 0%,
   rgba(246,249,252,1) 100%);

 border-bottom-color: #f6f9fc;

 border-right-image: linear-gradient(to bottom,
   rgba(155,156,157,1) 0%,
   rgba(246,249,252,1) 100%);

 border-style: solid;
}

2 个答案:

答案 0 :(得分:0)

虽然只是在Chrome中工作,但Firefox和IE都无法正常工作。

background: linear-gradient(to bottom,
  rgba(129,232,117,1) 0%,
  rgba(129,232,117,1) 50%,
  rgba(62,179,48,1) 51%,
  rgba(62,179,48,1) 100%);
border-image: linear-gradient(to bottom,
  rgba(155,156,157,1) 0%,
  rgba(246,249,252,1) 100%) 25 30 10 20 repeat;
border-image-repeat: stretch;
border-width: 4px;

应该注意的是,没有border-left-image和相关的属性;遗憾的是,这不是更好的CSS属性之一。

答案 1 :(得分:0)

您可以叠加2个渐变并使用background-sizepadding&amp; background-clip来绘制border

&#13;
&#13;
.button-style {
  background: linear-gradient(to bottom, rgba(129, 232, 117, 1) 0%, rgba(129, 232, 117, 1) 50%, rgba(62, 179, 48, 1) 51%, rgba(62, 179, 48, 1) 100%) no-repeat
  /* use for background */
  , linear-gradient(to bottom, rgba(155, 156, 157, 1) 0%, rgba(246, 249, 252, 1) 100%)
  /* use for border */
  ;
  background-size: 100% 100%, auto auto;
  background-clip: content-box, border-box;
  padding: 3px;
}
html {
  padding: 3em;
  background: gray;
&#13;
<a class="button-style">Evil Whales</a>
&#13;
&#13;
&#13;