【问题标题】:add inner box shadow on stroke width progress bar在笔划宽度进度条上添加内框阴影
【发布时间】:2021-10-25 05:59:47
【问题描述】:

我有一个带有 svg 样式的 css 和 html 用于圆形进度条,我想在附加的屏幕截图中添加浅灰色圆圈中的内框阴影,如何在笔画宽度 css 中添加内框阴影。[![

.progress-bar .base-circle-bar {
    stroke: #f5f4f4;
    fill: transparent;
    stroke-width: 28;
    r: 120;
    cx: 149;
    cy: 136;
}
.progress-bar .progress-circle-bar {
    stroke: #ffc20e;
    fill: transparent;
    stroke-width: 28;
    stroke-linecap: round;
    r: 122;
    cx: 161;
    cy: 140;
    stroke-dasharray: 476.522083;
    stroke-dashoffset: 310.38935382;
    transform: rotate(-32deg);
    transform-origin: 50% 50%;
}
<svg class="progress-bar">
      <circle class="base-circle-bar" />
      <circle class="progress-circle-bar" />
</svg>

]2]2

【问题讨论】:

    标签: html css svg shadow


    【解决方案1】:

    这样的?

    • 修改flood-color改变阴影颜色。
    • 通过调整stdDeviation 更改阴影模糊

    .progress-bar {
      width: 300px;
      height: 280px;
    }
    
    .progress-bar .base-circle-bar {
        stroke: #f5f4f4;
        fill: transparent;
        stroke-width: 28;
        r: 120;
        cx: 149;
        cy: 136;
        filter: url(#inset-shadow);
    }
    .progress-bar .progress-circle-bar {
        stroke: #ffc20e;
        fill: transparent;
        stroke-width: 28;
        stroke-linecap: round;
        r: 120;
        cx: 149;
        cy: 136;
        stroke-dasharray: 476.522083;
        stroke-dashoffset: 310.38935382;
        transform: rotate(-32deg);
        transform-origin: 149px 136px;
    }
    <svg class="progress-bar">
      <defs>
        <filter id="inset-shadow">
          <feFlood flood-color="#ccc"/>
          <feComposite operator="out" in2="SourceAlpha"/>
          <feGaussianBlur stdDeviation="4"/>
          <feComposite operator="in" in2="SourceGraphic"/>
          <feBlend mode="multiply" in="SourceGraphic" />
        </filter>
      </defs>
      
      <circle class="base-circle-bar" />
      <circle class="progress-circle-bar" />
    </svg>

    【讨论】:

    • 非常感谢您并给予您宝贵的时间,它工作正常,正如我想要的那样
    【解决方案2】:

    你可以使用这个网站进行神经拟态:https://neumorphism.io/#e0e0e0

    或者你可以使用它:

    <svg width="360" height="360" viewBox="0 0 180 180">
      <defs>
    
        <!-- Gaussian blur filter used to soften the shadow edges -->
        <filter id="blur" filterUnits="userSpaceOnUse" x="-90" y="-90"
                width="180" height="180">
          <feGaussianBlur in="SourceGraphic" stdDeviation="1" />
        </filter>
    
        <!-- Annular clip path for the progress meter background -->
        <clipPath id="ring" clip-rule="evenodd">
          <path d="M0-81A81 81 0 0 1 0 81A81 81 0 0 1 0-81z
                   M0-63A63 63 0 0 1 0 63A63 63 0 0 1 0-63z" />
        </clipPath>
    
      </defs>
    
      <!-- Set orgin to centre of drawing -->
      <g transform="translate(90,90)">
    
        <!-- Start with pale yellow background -->
        <rect x="-90" y="-90" width="180" height="180" fill="#e8e0ce"
              stroke="none" />
    
        <!-- Draw the progress ring on top, and clip using the above clip path -->
        <g clip-path="url(#ring)">
    
          <!-- Dark grey background -->
          <rect x="-85" y="-85" width="170" height="170" fill="#433"
                stroke="none" />
    
          <!-- Lighter grey circle with blur filter applied -->
          <circle cx="0" cy="2.5" r="72" stroke="#655" stroke-width="18"
                  stroke="#655" fill="none" filter="url(#blur)"/>
    
        </g>
    
        <!-- Progress bar and text -->
        <path class="main-arc" d="M 0 -72 A 72 72 0 1 1 -4.52 -71.86"
              style="stroke-dasharray: 452.389; stroke-dashoffset: 366.435;"
              fill="transparent" stroke-width="18" stroke="#b65"
              stroke-linecap="round" />
        <text x="0" y="0" font-size="40" font-family="'Trebuchet MS', sans-serif"
              fill="#655" text-anchor="middle" dominant-baseline="central">
          20%
        </text>
    
      </g>
    </svg>

    或者这个:

    <svg width="180" height="180" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <defs>
    <filter id="inset-shadow">
      <feFlood flood-color="black"/>
      <feComposite operator="xor" in2="SourceGraphic"/>
      <feGaussianBlur stdDeviation="1"/>
      <feComposite operator="in" in2="SourceGraphic" result="map"/>
      <feDiffuseLighting lighting-color="white" surfaceScale="2" diffuseConstant="1">
      <feSpotLight x="-30" y="-30" z="230"/>
    </feDiffuseLighting>
      <feBlend mode="multiply" in="SourceGraphic" />
      <feComposite operator="in" in2="SourceGraphic"/>
    
    </filter>
    </defs>
    
      <circle filter="url(#inset-shadow)" cx="90" cy="90" r="72" fill="none" stroke="#ddd" stroke-width="18"></circle>
      <path class="main-arc" d="M 90 18 A 72 72 0 1 1 85.47908259388944 18.142075553164446" fill="transparent" stroke-width="18" stroke="black" stroke-linecap="round" style="stroke-dasharray: 452.389; stroke-dashoffset: 366.435;">
      </path>
    </svg>

    【讨论】:

    • 感谢您的回复,但我想要描边宽度的内阴影。我在进度条中使用了笔画宽度
    • 感谢您宝贵的时间,非常感谢
    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 2022-12-08
    • 1970-01-01
    • 2017-03-16
    • 2013-08-02
    • 1970-01-01
    • 2017-01-15
    相关资源
    最近更新 更多