这是一种使用径向背景图像的方法。它可以使背景透明,并且在Firefox和Chrome浏览器中都能正常工作。
你可以点击这里查看具体实现。
.player {
width: 480px;
height: 80px;
border-radius: 40px;
background-image: radial-gradient(circle at 38px 40px, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 40px, blue 40px);
color: #FFF;
}
<div class="player"></div>
你可以使用before
伪元素来提供“切除”效果
.player {
width: 480px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#0000FF;
position:relative;
color:#FFF;
}
.player:before
{
width: 80px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#FFF;
display:inline-block;
vertical-align: middle;
margin-right: 10px;
content: '';
}
<div class="player">Some Content</div>
clip-path
马上就要来了:http://caniuse.com/#feat=css-clip-path 和 https://css-tricks.com/almanac/properties/c/clip/ - Jon P.wrapper {
width: 500px;
height: 103px;
background-color: red;
padding-top: 15px;
}
.player {
width: 480px;
height: 83px;
margin-left: 10px;
border-top-right-radius: 40px;
border-bottom-right-radius: 40px;
border: 1px solid black;
border-left: none;
background-color: blue;
-webkit-mask-image: radial-gradient(circle at left, transparent 0, transparent 40px, black 41px);
}
<div class="wrapper"><div class="player"></div></div>
Jon P的答案已经接近了解决方法 - 但before元素可以用于在主div左侧制作一个透明圆形,阴影产生所需的剪裁效果。
body {
/* You can change the background colour to verify that this is truly transparent */
background-color: pink;
}
.player {
/* Just a normal box */
width: 480px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:#0000FF;
position:relative;
color:#FFF;
/* Move the box right so that we can see the cutout to the left */
margin-left: 40px;
}
.player:before
{
width: 80px;
height: 80px;
border-radius:0 40px 40px 0;
background-color:transparent;
display:inline-block;
vertical-align: middle;
margin-right: 10px;
content: '';
/* This is the cutout: */
box-shadow: 40px 0px #00f;
position: relative;
left: -80px;
}
<div class="player">Some Content</div>
我也曾这样想,但我找到了更好的方法,我使用了SVG作为背景。它还有更好的响应性优势。我会把我的问题发到这里,让其他人也能得到同样的帮助。
* {
padding: 0;
margin: 0;
}
#sidebar {
width: 500px;
height: 100vh;
background: url(https://svgshare.com/i/XiH.svg) center right;
background-size: 150%;
}
<div id="sidebar"></div>
p {
width: 480px;
height: 80px;
border-radius: 1in;
box-shadow:inset -400px 0 #03214f,inset 9in 0 #fff;
}
<p>