can you make a section of a div transparent and affect its box-shadow

半城伤御伤魂 提交于 2019-11-30 00:01:56

问题


I have managed to make a part of my div transparent by following this example: http://jsfiddle.net/5VDLX/144/

HTML (JSFIDDLE)

<div class="container">
    <div class="shape"></div>
    <div class="circle"></div>
</div>

CSS (JSFIDDLE)

body{
    background: yellow;
}
.shape {
    width: 500px;
    height: 75px;
    background-color: transparent;
    background-image: -webkit-radial-gradient(50% 100%, circle, transparent 50px, black 0);
    background-image: radial-gradient(50% 100%, circle, transparent 50px, black 0);
}
.circle {
    width: 100px;
    height: 100px;
    background-color: transparent;
    border: 2px solid red; /* red for demonstration */
    border-radius: 50px;
    margin: -51px 0 0 199px; /* considering borders */
}

But the div has a box-shadow which i would like to follow the transparent half-circle instead of remaining square.

Can this be achieved? And if so, how?


回答1:


You can use the drop-shadow filter:

body {
  background: yellow;
}

.shape {
  width: 500px;
  height: 75px;
  background: radial-gradient(circle at 50% 100%, transparent 49px, black 50px);
  filter:drop-shadow(0 0 10px green);
}
<div class="container">
  <div class="shape"></div>
</div>


来源:https://stackoverflow.com/questions/51524222/can-you-make-a-section-of-a-div-transparent-and-affect-its-box-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!