【问题标题】:border radius for a clip path having border created from shadow具有从阴影创建的边框的剪辑路径的边框半径
【发布时间】:2020-10-16 18:08:04
【问题描述】:

我有这个顶部 div 是动态的形状,我需要在这些角上添加边框半径。 shape 由两个具有共享线性渐变背景的 div 组成。并且边框是使用阴影生成的。

这是我的代码。

#parent {
  width: max-content;
  background:linear-gradient(to bottom left, transparent,rgba(255,255,255,0.75),transparent,rgba(255,255,255,0.75),transparent,rgba(255,255,255,0.75)) yellow;
}

#pool-container {
  padding: 10px;
  width: 200px;
  margin: 0 5px 0 5px;
  display: flex;
  flex-direction: column;
  position: relative;
  filter: drop-shadow(0px -2px 0px black) drop-shadow(0px 2px 0px black) drop-shadow(-2px 0px 0px black) drop-shadow(2px 0px 0px black)
}

#side-step {
  height: 80px;
  width: 80px;
  transition: 1s all;
}

#pool-container:hover #side-step {
  margin-left: 120px;
}

#side-step,
#main-pool {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

#side-step::before,
#main-pool::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient( 120deg, rgba(248, 201, 129, 1) 0%, rgba(227, 76, 145, 1) 100%);
}

#main-pool {
  width: 100%;
  height: 150px;
}
<div id="pool-container">
  <div id="side-step"></div>
  <div id="main-pool"></div>
</div>

【问题讨论】:

    标签: html css svg


    【解决方案1】:

    这是一个想法,我将考虑在this previous answer 中使用的 SVG 过滤器。调整stdDeviation的值来控制半径:

    #parent {
      width: max-content;
      background:linear-gradient(to bottom left, transparent,rgba(255,255,255,0.75),transparent,rgba(255,255,255,0.75),transparent,rgba(255,255,255,0.75)) yellow;
    }
    
    #pool-container {
      padding: 10px;
      width: 200px;
      margin: 0 5px 0 5px;
      display: flex;
      flex-direction: column;
      position: relative;
      filter: url('#goo') drop-shadow(0px -2px 0px black) drop-shadow(0px 2px 0px black) drop-shadow(-2px 0px 0px black) drop-shadow(2px 0px 0px black) 
    }
    
    #side-step {
      height: 80px;
      width: 80px;
      transition: 1s all;
    }
    
    #pool-container:hover #side-step {
      margin-left: 120px;
    }
    
    #side-step,
    #main-pool {
      clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    }
    
    #side-step::before,
    #main-pool::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient( 120deg, rgba(248, 201, 129, 1) 0%, rgba(227, 76, 145, 1) 100%);
    }
    
    #main-pool {
      width: 100%;
      height: 150px;
    }
    <div id="pool-container">
      <div id="side-step"></div>
      <div id="main-pool"></div>
    </div>
    
    <svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
        <defs>
            <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />    
                <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
                <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
            </filter>
        </defs>
    </svg>

    【讨论】:

    • 非常感谢,它在 Firefox 上运行良好,但在 chrome 边框上消失了我有最新版本的 chrome,并且根据 caniuse.com 支持 fegaussianblur
    • 黑色有效,但是当我将颜色更改为此 #5a95b4 时,它适用于 firefox 但不适用于 chrome
    • 当我将 url("#goo") 放入过滤器时会出现色差。我将颜色更改为最近的网络安全颜色,但仍然存在
    • chrome 中的颜色不透明度好像不全。
    • @ZarghamKhan 尝试使用额外的容器:jsfiddle.net/qc8tv0jo
    猜你喜欢
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多