我想使用border-corner-shape
属性来实现以下形状。但它不起作用。
我的代码如下:
.left-1 {
background-color: #3498DB;
border-corner-shape: scoop;
border-radius: 30px;
width: 200px;
height: 200px;
}
<div class="left-1"></div>
为什么不起作用?
答案 0 :(得分:10)
使用径向渐变:
这是使用径向渐变实现边角角落效果的另一种替代方法。在这种方法中,我们使用多个径向渐变并将它们定位在角落。
.border-scoop {
height: 300px;
width: 300px;
background: -webkit-radial-gradient(0% 100%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(0% 0%, circle, transparent 15%, steelblue 15%) no-repeat, -webkit-radial-gradient(100% 100%, circle, transparent 15%, steelblue 15%) no-repeat;
background: radial-gradient(circle at 0% 100%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 0% 0%, transparent 15%, steelblue 15%) no-repeat, radial-gradient(circle at 100% 100%, transparent 15%, steelblue 15%) no-repeat;
background-position: 0% 100%, 100% 0%, 0% 0%, 100% 100%;
background-size: 75% 75%;
}
body {
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
&#13;
<div class="border-scoop"></div>
&#13;
使用剪辑路径:
使用clip-path
也可以实现Scooped border corner效果。纯CSS版本仅支持基本形状(圆形,多边形,椭圆形等),不支持路径或形状组合,但可以使用SVG(内联/外部)。
.border-scoop {
width: 200px;
height: 200px;
background-color: #3498DB;
-webkit-clip-path: url(#scoop);
clip-path: url(#scoop);
}
body {
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
&#13;
<svg width='0' height='0'>
<defs>
<clipPath id='scoop' clipPathUnits='objectBoundingBox'>
<path d='M0.2,0 A0.2,0.2 0 0,1 0,0.2
L0,0.8 A0.2,0.2 0 0,1 0.2,1
L0.8,1 A0.2,0.2 0 0,1 1,0.8
L1,0.2 A0.2,0.2 0 0,1 0.8,0z' />
</clipPath>
</defs>
</svg>
<div class='border-scoop'></div>
&#13;
带有Box Shadow的透明勺:
下面的代码片段是GCyrillus的变种&#39;回答,这需要一个额外的元素,但即使页面的背景不是纯色也会有效。然而,该方法仍然具有与另一个答案中提到的相同的固定和已知大小限制。
必须注意的是,框阴影具有比径向渐变更好的浏览器支持。
.border-scoop{
height: 300px;
width: 300px;
position: relative;
overflow: hidden;
}
.inner{
position: absolute;
top: 0px; left: 0px;
height: 100%;
width: 100%;
}
.border-scoop:before, .border-scoop:after, .inner:after, .inner:before{
position: absolute;
content: '';
height: 30%; width: 30%;
border-radius: 50%;
background: transparent;
box-shadow: 0px 0px 0px 210px steelblue;
}
.border-scoop:before{
top: -15%; left: 85%;
}
.border-scoop:after{
top: -15%; left: -15%;
}
.inner:after{
top: 85%; left: 85%;
}
.inner:before{
top: 85%; left: -15%;
}
body{
background: -webkit-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
&#13;
<div class="border-scoop">
<div class="inner"></div>
</div>
&#13;
答案 1 :(得分:7)
此功能(border-corner-shape : curve | scoop | bevel | notch
)尚未实施(尚未实验),因此不适用于任何现有浏览器。
答案 2 :(得分:5)
如果该框具有已知且固定大小,则可以使用一个伪元素和box-shadow
伪造它,甚至可以绘制弯曲的边框:
<强> DEMO 强> HTML:
<div class="scoop">
<p>another single div shaped</p>
</div>
<div class="scoop border">
<p>another single div shaped</p>
</div>
CSS:
.scoop {
position:relative;
height:200px;
width:200px;
overflow:hidden;
}
body {
background:#F3F3F3;/* color reused in pseudo element */
}
.scoop:before{
content:'';
position:absolute;
left:0;
margin:-20px;
height:40px;
width:40px;
border-radius:100%;
background:#F3F3F3;
box-shadow:200px 0 0 #F3F3F3,
0 200px 0 #F3F3F3,
200px 200px 0 #F3F3F3,
0 0 0 500px #2798DE;/* here we draw background-color of parent */
}
div > * {
margin:auto;
position:relative;/* to draw on top of shadowed pseudo element */
}
并绘制边框,让我们添加一些额外的阴影:
div.border {
box-shadow:
23px 0 0 -20px,/* 23px =>(towards right) width of pseudo seen + fakeborder width 0 0 -20px => reduce size shadow of 20px */
-23px 0 0 -20px,
0 23px 0 -20px,
0 -23px 0 -20px;
}
div.border:before {
box-shadow:
0 0 0 3px,/* draw 3px unblured shadow */
200px 0 0 #F3F3F3,/* mask of main background-color */
200px 0 0 3px ,
0 200px 0 #F3F3F3,
0 200px 0 3px,
200px 200px 0 #F3F3F3,
200px 200px 0 3px,
0 0 0 500px #2798DE;
}