css - 如何在图像周围做径向线渐变并设置它的百分比? CSS 或 SVG 或任何东西都可以解决问题

标签 css radial-gradients

我需要开发下一个样式:enter image description here

图像周围的渐变具有不同的颜色并且可以是未完成的。

我该怎么做并设置它的百分比?

对于要求代码的人:

body {
  height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background: #222;
}

.module-border-wrap {
  max-width: 250px;
  padding: 1rem;
  position: relative;
  background: linear-gradient(to right, red, purple);
  padding: 3px;
}

.module {
  background: #222;
  color: white;
  padding: 2rem;
}

最佳答案

我相信您需要使用 SVG。这是您可以应用于路径的渐变。您也可以使用 stroke-dasharray 和 stroke-offset 来获得半圆。

 <svg height="150" width="150">
  <defs>
    <radialGradient id="grad1" cx="80%" cy="20%" r="100%" fx="100%" fy="50%">
      <stop offset="0%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
      <stop offset="100%" style="stop-color:rgb(0,200,255);stop-opacity:1" />
    </radialGradient>
  </defs>
  <ellipse cx="100" cy="100" rx="30" ry="30" stroke="url(#grad1)" stroke-width="10" fill="none" stroke-linecap="round" stroke-dasharray="1000" stroke-dashoffset="840"/>
</svg

stroke-dashoffset=""是您可以调整以增大或减小圆圈大小的数字。这是有效的,因为你正在创建一条虚线,它有很远的破折号,所以它只显示一个破折号的一部分。如果您偏移该破折号,则可以沿路径移动它。

关于css - 如何在图像周围做径向线渐变并设置它的百分比? CSS 或 SVG 或任何东西都可以解决问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58920708/

相关文章:

html - margin 自动失败 IE11

javascript - jQuery 文本扩展 : max height and scrollbar

html - Firebug 显示的 <div> 比我在源代码中看到的要多

python - 放置具有可变密度的点

python - 如何用python创建透明的径向渐变?

javascript - 用 JS 移动 div(已编辑)

css - 菜单项 CSS 旁边的 Logo

safari - 为什么 webkit 径向渐变在 Safari 中不起作用?

css - 使用径向渐变的动态印章效果

css - 为什么当我使用径向渐变(circle at)时,不透明的边框会在圆圈内形成一个正方形?