如果形状背景是纯色而页面背景不是,则可以使用伪元素和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;
}Run Code Online (Sandbox Code Playgroud)
<div class='shape'></div>Run Code Online (Sandbox Code Playgroud)
您还可以使用SVG path元素实现相同的效果,如下面的代码段所示.
div {
height: 300px;
width: 150px;
}
svg path {
fill: blue;
}
body {
background: linear-gradient(chocolate, brown);
height: 100vh;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
372 次 |
| 最近记录: |