带阴影和底部边框的圆形 CSS 形状
Circular CSS shape with drop shadow and border-bottom
更新 所以我刚刚发现了椭圆边界半径。获得了与我一直在寻找的几乎相同的结果,但边框因省略号而变粗,因此如果有人知道更好的方法,我仍在寻找。 Here's my JSfiddle - Result looks like this
fiddle
中使用的代码
border-bottom: 3px solid green;
-moz-border-radius-bottomleft: 70% 40px;
-webkit-border-bottom-left-radius: 70% 40px;
-webkit-box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;
box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;
原版POST
我想知道是否可以创建类似于下面的形状
形状将与图像重叠。我知道我可以用 border-bottom-left-radius
创建一个矩形 DIV 然后给它 border-bottom: 3px solid green
和 drop-shadow
,但是边界半径并没有真正达到相同的 "angle"如上图所示..
我以为我会只使用 SVG,但我不能有阴影..所以如果有任何方法可以用阴影创建这样的形状,我愿意接受所有建议。谢谢
边框-半径
您可以在右侧添加相同的样式 border-radius
,占用剩余的 30%。
body {
background: lightblue;
}
#box {
width: 500px;
height: auto;
border-bottom: 3px solid green;
-moz-border-radius-bottomleft: 70% 40px;
-webkit-border-bottom-left-radius: 70% 40px;
-moz-border-radius-bottomright: 30% 20px;
-webkit-border-bottom-right-radius: 30% 20px;
-webkit-box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
}
<img id="box" src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
剪辑路径
您也可以考虑使用 clip-path
来获取您想要的区域。遗憾的是,这不允许 box-shadows
body {
background: lightblue;
}
.container {
-webkit-clip-path: ellipse(100% 56% at 71% 39%);
clip-path: ellipse(100% 56% at 71% 39%);
width: 500px;
height: auto;
background: green;
}
img {
-webkit-clip-path: ellipse(100% 56% at 71% 39%);
clip-path: ellipse(100% 56% at 71% 39%);
width: 500px;
height: auto;
}
<div class="container">
<img src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
</div>
SVG
您也可以使用 SVG 实现所需的形状。
body {
background: lightblue;
}
<svg width="500" height="250" viewBox="0 0 100 50">
<defs>
<pattern id="image" patternUnits="userSpaceOnUse" height="50" width="100">
<image x="0" y="0" height="50" width="100" xlink:href="https://31.media.tumblr.com/cd4319a4a4ba642649bcf7936d48eec8/tumblr_inline_mn089qqjI71qz4rgp.png"></image>
</pattern>
<filter id="blur" x="0" y="0" width="100%" height="110%">
<feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<g class="curve">
<path fill="url(#image)" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1
L-1,40
C-1,40 60,45 101,42
L101,-1z" />
</g>
</svg>
符合使用要求的 SVG
body {
background: lightblue;
margin: 0;
padding: 0;
}
<svg width="100%" viewBox="0 0 100 50" preserveAspectRatio="none" height="150px">
<defs>
<filter id="blur" x="0" y="0" width="100%" height="110%">
<feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<path fill="#ffffff" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1
L-1,40
C-1,40 60,45 101,42
L101,-1z" />
</svg>
我使用了内阴影而不是 border-bottom,它确实使线条变粗(您可以尝试将 box-shadow:inset
的第一个值设置为 1 或 2px,以便将绿色阴影向右移动). JSFiddle
HTML
<div class="container">
<div class="line-shadow"></div>
<div class="line"></div>
</div>
CSS
.container {
position: relative;
width: 900px;
height: 600px;
overflow: hidden;
}
.line-shadow{
position: absolute;
bottom: 21px;
left: -19px;
width: 1000px;
height: inherit;
border-bottom-left-radius: 800px 150px;
border-bottom-right-radius: 800px 30px;
-webkit-box-shadow: 0 0 12px 1px #000000;
box-shadow: 0 0 12px 1px #000000;
background-image: url(http://filepic.ru/file/1438005661.jpg);
background-size: cover;
}
.line {
position: absolute;
bottom: 20px;
left: -20px;
width: 1000px;
height: inherit;
border-bottom-left-radius: 800px 150px;
border-bottom-right-radius: 800px 30px;
-webkit-box-shadow:inset 0 0 0 4px #6db43d;
box-shadow:inset 0 0 0 4px #6db43d;
}
有一个明显的缺点 - div 太多。但是你可以尝试使用 css ::after
而不是 div.
更新 所以我刚刚发现了椭圆边界半径。获得了与我一直在寻找的几乎相同的结果,但边框因省略号而变粗,因此如果有人知道更好的方法,我仍在寻找。 Here's my JSfiddle - Result looks like this
fiddle
中使用的代码border-bottom: 3px solid green;
-moz-border-radius-bottomleft: 70% 40px;
-webkit-border-bottom-left-radius: 70% 40px;
-webkit-box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;
box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;
原版POST
我想知道是否可以创建类似于下面的形状
形状将与图像重叠。我知道我可以用 border-bottom-left-radius
创建一个矩形 DIV 然后给它 border-bottom: 3px solid green
和 drop-shadow
,但是边界半径并没有真正达到相同的 "angle"如上图所示..
我以为我会只使用 SVG,但我不能有阴影..所以如果有任何方法可以用阴影创建这样的形状,我愿意接受所有建议。谢谢
边框-半径
您可以在右侧添加相同的样式 border-radius
,占用剩余的 30%。
body {
background: lightblue;
}
#box {
width: 500px;
height: auto;
border-bottom: 3px solid green;
-moz-border-radius-bottomleft: 70% 40px;
-webkit-border-bottom-left-radius: 70% 40px;
-moz-border-radius-bottomright: 30% 20px;
-webkit-border-bottom-right-radius: 30% 20px;
-webkit-box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
}
<img id="box" src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
剪辑路径
您也可以考虑使用 clip-path
来获取您想要的区域。遗憾的是,这不允许 box-shadows
body {
background: lightblue;
}
.container {
-webkit-clip-path: ellipse(100% 56% at 71% 39%);
clip-path: ellipse(100% 56% at 71% 39%);
width: 500px;
height: auto;
background: green;
}
img {
-webkit-clip-path: ellipse(100% 56% at 71% 39%);
clip-path: ellipse(100% 56% at 71% 39%);
width: 500px;
height: auto;
}
<div class="container">
<img src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
</div>
SVG
您也可以使用 SVG 实现所需的形状。
body {
background: lightblue;
}
<svg width="500" height="250" viewBox="0 0 100 50">
<defs>
<pattern id="image" patternUnits="userSpaceOnUse" height="50" width="100">
<image x="0" y="0" height="50" width="100" xlink:href="https://31.media.tumblr.com/cd4319a4a4ba642649bcf7936d48eec8/tumblr_inline_mn089qqjI71qz4rgp.png"></image>
</pattern>
<filter id="blur" x="0" y="0" width="100%" height="110%">
<feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<g class="curve">
<path fill="url(#image)" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1
L-1,40
C-1,40 60,45 101,42
L101,-1z" />
</g>
</svg>
符合使用要求的 SVG
body {
background: lightblue;
margin: 0;
padding: 0;
}
<svg width="100%" viewBox="0 0 100 50" preserveAspectRatio="none" height="150px">
<defs>
<filter id="blur" x="0" y="0" width="100%" height="110%">
<feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<path fill="#ffffff" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1
L-1,40
C-1,40 60,45 101,42
L101,-1z" />
</svg>
我使用了内阴影而不是 border-bottom,它确实使线条变粗(您可以尝试将 box-shadow:inset
的第一个值设置为 1 或 2px,以便将绿色阴影向右移动). JSFiddle
HTML
<div class="container">
<div class="line-shadow"></div>
<div class="line"></div>
</div>
CSS
.container {
position: relative;
width: 900px;
height: 600px;
overflow: hidden;
}
.line-shadow{
position: absolute;
bottom: 21px;
left: -19px;
width: 1000px;
height: inherit;
border-bottom-left-radius: 800px 150px;
border-bottom-right-radius: 800px 30px;
-webkit-box-shadow: 0 0 12px 1px #000000;
box-shadow: 0 0 12px 1px #000000;
background-image: url(http://filepic.ru/file/1438005661.jpg);
background-size: cover;
}
.line {
position: absolute;
bottom: 20px;
left: -20px;
width: 1000px;
height: inherit;
border-bottom-left-radius: 800px 150px;
border-bottom-right-radius: 800px 30px;
-webkit-box-shadow:inset 0 0 0 4px #6db43d;
box-shadow:inset 0 0 0 4px #6db43d;
}
有一个明显的缺点 - div 太多。但是你可以尝试使用 css ::after
而不是 div.