2

我正在尝试使用源是径向渐变的边框图像。我已经看过很多带有图像的示例,但没有看到带有径向渐变的示例。

My CodePen中的完整示例

#main {
  width: 200px;
  border: 8px solid red;
  padding: 10px;
  border-image:
      radial-gradient( farthest-corner, #777 50%, #7770 60%)  /* source */
      28 /                    /* slice */
      8px 8px 8px 8px /    /* width */
      4px 4px 4px 4px       /* outset */
      round;                  /* repeat */
}

我只是想用间隔几个像素的小圆圈围绕盒子,最好使用纯 CSS 解决方案。虽然我很高兴听到其他问题

4

1 回答 1

1

你可以用这样的背景来做:

#main {
  width: 200px;
  padding:10px;
  background: 
   radial-gradient(circle at center, #777 60%, transparent 61%) top left/10px 10px repeat-x,
   radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-x;
}
<div id="main">This element is surrounded by a radial-gradient-based border image!</div>

如果你想要所有的面,你可以这样做:

#main {
  width: 200px;
  padding:13px 10px;
  background: 
   radial-gradient(circle at center, #777 60%, transparent 61%) top left/10px 10px repeat-x,
   radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-x,
   radial-gradient(circle at center, #777 60%, transparent 61%) bottom left/10px 10px repeat-y,
   radial-gradient(circle at center, #777 60%, transparent 61%) bottom right/10px 10px repeat-y;
}
<div id="main">This element is surrounded by a radial-gradient-based border image!</div>

于 2018-07-03T19:10:49.193 回答