CSS - 渐变边框从到

问题描述 投票:0回答:1

我想让我的整个div部分有渐变的边框。这是我的代码。

.usermanagement {
  -webkit-border-image: -webkit-gradient(
      linear,
      left top,
      left bottom,
      from(#fff),
      to(#afd4ec),
      color-stop(0.2, #afd4ec)
    )
    0 0 0 0 repeat repeat;
}

效果和我想要的完全一样 但只是顶部的效果

enter image description here

然后全部变成浅蓝色,然后像这样完成。enter image description here

没有这个渐变效果 我想在该部分的底端做出和顶部一样的效果。这怎么可能?

javascript html css sass gradient
1个回答
1
投票

你可以像下面这样尝试,确保正确设置不同的值。

.box {
  height:50px; /* this need to be a multiple of 10 for the effect to work */
  border-top:   10px solid;
  border-bottom:10px solid;
  background:#f2f2f2;
  border-image:repeating-linear-gradient(#fff 0,red 10px) 10;
}
<div class="box"></div>

你也可以用多个背景来做。

.box {
  height:50px;
  border-top:10px solid transparent;
  border-bottom:10px solid transparent;
  background:
   linear-gradient(#fff ,red ) top,
   linear-gradient(#fff ,red ) bottom, /* use (red, #fff) here for the opposite effect */
   #f2f2f2;
  background-size:100% 10px;
  background-origin:border-box;
  background-repeat:no-repeat;
}
<div class="box"></div>
© www.soinside.com 2019 - 2024. All rights reserved.