边框半径 具有从阴影创建的边框的剪辑路径

border radius for a clip path having border created from shadow

提问人:Zargham Khan 提问时间:6/26/2020 更新时间:6/26/2020 访问量:501

问:

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

enter image description here

这是我的代码。

#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

评论


答:

4赞 Temani Afif 6/26/2020 #1

这里有一个想法,我将考虑我在上一个答案中使用的 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>

评论

0赞 Zargham Khan 6/27/2020
非常感谢,它在 firefox 上运行良好,但在 chrome 边框上消失,我有最新版本的 chrome 和 fegaussianblur 支持 caniuse.com
0赞 Zargham Khan 6/27/2020
黑色有效,但是当我将颜色更改为此 #5a95b4 时,它适用于Firefox,但不适用于Chrome
0赞 Zargham Khan 6/27/2020
当我将 url(“#goo”) 放在过滤器中时会出现色差。我将颜色更改为最接近的 WebSafe 颜色,但仍然在那里
0赞 Zargham Khan 6/27/2020
Chrome中的颜色不透明度似乎并不完整。
1赞 Temani Afif 6/27/2020
@ZarghamKhan尝试使用额外的容器:jsfiddle.net/qc8tv0jo