【发布时间】:2015-12-13 21:52:01
【问题描述】:
【问题讨论】:
-
页面的背景是纯色还是渐变/图像?如果是纯色就比较容易了。
-
@Harry 该框将呈现在温和的透明覆盖层上。我需要保持盒子周围的透明度
-
形状本身怎么样?是纯蓝色背景吗?
标签: html css svg css-shapes
【问题讨论】:
标签: html css svg css-shapes
鉴于形状背景是纯色而页面背景不是,您可以使用伪元素和具有高传播半径的box-shadow 创建形状。这是一个 hackish 解决方案,但可以在大多数浏览器上运行,因为 box shadow 有很好的支持。
div{
position: relative;
height: 300px;
width: 150px;
border-radius: 12px;
overflow: hidden;
}
div:after{
position: absolute;
content: '';
height: 30px;
bottom: -15px;
width: 100%;
left: 0px;
box-shadow: 0px 0px 0px 500px blue;
border-radius: 12px;
}
body{
background: linear-gradient(chocolate, brown);
height: 100vh;
}
<div class='shape'></div>
您也可以使用 SVG path 元素实现相同的效果,如下面的 sn-p 所示。
div {
height: 300px;
width: 150px;
}
svg path {
fill: blue;
}
body {
background: linear-gradient(chocolate, brown);
height: 100vh;
}
<svg viewBox='0 0 150 300' height='0' width='0'>
<defs>
<g id='shape'>
<path d='M0,12 A12,12 0 0,1 12,0 L138,0 A12,12 0 0,1 150,12 L150,300 A12,12 0 0,0 138,288 L12,288 A12,12 0 0,0 0,300z' id='fill' />
</g>
</defs>
</svg>
<div class='shape'>
<svg viewBox='0 0 150 300' preserveAspectRatio='none' vector-effect='non-scaling-stroke'>
<use xlink:href='#shape' />
</svg>
</div>
【讨论】: