CSS shape with inset curve and transparent backgro

2020-01-29 02:00发布

I need to create a CSS shape like this image..

enter image description here

Please check this fiddle of my work I have created something like that, but I cannot give a curve to it.

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

Can anyone help me?

2条回答
一纸荒年 Trace。
2楼-- · 2020-01-29 02:11

You can use a pseudo element with border-radius and background-shadows to create the curve and enable a transparent background for the curve.

Output :

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

查看更多
ゆ 、 Hurt°
3楼-- · 2020-01-29 02:28

Variant #01:

CSS3 linear-gradient() can draw this background as well:

CSS:

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

Output Image:

enter image description here

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;
}
<div>
  
</div>

Variant #02:

We can use :before and :after pseudo elements and use css3 transformation to make this shape with round corners.

Output Image with round corners

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;
}
<div>

</div>

查看更多
登录 后发表回答