具有插入曲线和透明背景的CSS形状

时间:2014-07-11 11:42:23

标签: html css css3 svg css-shapes

我需要创建一个像这个图像的CSS形状..

enter image description here

请查看我的fiddle我的工作 我创造了类似的东西,但我不能给它一个曲线。

#shape {     
    border-left: 70px solid transparent;
    border-top: 100px solid red;
    height: 0;
    width: 200px;
} 

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:7)

您可以使用包含border-radius和background-shadows的伪元素来创建曲线,并为曲线启用透明背景

输出:

CSS Shape with thransparent inset curve

#shape {
  width: 300px; height: 100px;
  position: relative;
  overflow: hidden;
}

#shape:before {
  content: '';
  position: absolute;
  top: 10%; right: 0;
  width: 300%;
  padding-bottom: 300%;
  border-radius: 100%;
  background: none;
  box-shadow: 10px -10px 5px 300px #F15723;
  z-index: -1;
}

body{background:url(https://farm9.staticflickr.com/8461/8048823381_0fbc2d8efb.jpg);background-size:cover;}
<div id="shape"></div>

demo

答案 1 :(得分:0)

变体#01:

CSS3 linear-gradient()也可以绘制此背景:

<强> CSS:

div {
  background: linear-gradient(45deg, transparent 50px, tomato 50px);
}

输出图片:

enter image description here

&#13;
&#13;
body {
  background: linear-gradient(lightgreen, green);
  min-height: 100vh;
  margin: 0;
}
div {
  background: linear-gradient(45deg, transparent 50px, tomato 50px);
  height: 150px;
  margin: 20px;
  width: 400px;
}
&#13;
<div>
  
</div>
&#13;
&#13;
&#13;

变体#02:

我们可以使用:before:after伪元素,并使用css3转换来制作带圆角的形状。

Output Image with round corners

&#13;
&#13;
body {
  background: linear-gradient(lightgreen, green);
  min-height: 100vh;
  margin: 0;
}
div {
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  height: 150px;
  margin: 20px;
  width: 400px;
}
div:before {
  border-radius: 0 0 10px 10px;
  transform-origin: 100% 0;
  transform: skewY(45deg);
  background: tomato;
  position: absolute;
  width: 45px;
  z-index: -1;
  content: '';
  bottom: -5px;
  left: 0;
  top: 0;
}
div:after {
  border-radius: 0 10px 10px 10px;
  background: tomato;
  position: absolute;
  content: '';
  left: 35px;
  bottom: 0;
  right: 0;
  top: 0;
}
&#13;
<div>

</div>
&#13;
&#13;
&#13;