Curve bottom side of the div to the inside with CSS

后端 未结 2 1809
耶瑟儿~
耶瑟儿~ 2020-11-22 13:37

I would like to curve the bottom side of this rectangle div/background with CSS, so the result is something like this:

Does someone have an idea perhaps how it cou

2条回答
  •  野性不改
    2020-11-22 13:58

    Simply use border-radius and rely on some overflow. You can also consider pseudo element to avoid extra markup:

    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      background: lightblue;
      position: relative;
      overflow: hidden;
    }
    
    .container:after {
      content: "";
      position: absolute;
      height: 80px;
      left: -10%;
      right: -10%;
      border-radius: 50%;
      bottom: -25px;
      background: #fff;
    }


    You can also use radial-gradient if you want a transparent shape:

    body {
      background: pink;
    }
    
    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      background: radial-gradient(110% 50% at bottom, transparent 50%, lightblue 51%);
    }


    And here is another way using clip-path

    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      background-color: lightblue;
      position: relative;
      overflow: hidden;
    }
    
    .container:after {
      content: "";
      position: absolute;
      bottom: 0;
      right: -5%;
      left: -5%;
      height: 120px;
      background: #fff;
      -webkit-clip-path: ellipse(50% 60% at 50% 100%);
      clip-path: ellipse(50% 60% at 50% 100%);
    }

    You can also consider SVG:

    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      background: url("data:image/svg+xml,") top center/auto 700px no-repeat;
    }


    Here is an example if you want also to add border around your shape:

    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      border: 2px solid #000;
      border-bottom: 0;
      background: lightblue;
      position: relative;
      overflow: hidden;
    }
    
    .container:after {
      content: "";
      position: absolute;
      height: 80px;
      left: -10%;
      right: -10%;
      border-radius: 50%;
      bottom: -62px;
      background: #fff;
      z-index: 2;
    }
    
    .container:before {
      content: "";
      position: absolute;
      height: 82px;
      left: -10%;
      right: -10%;
      border-radius: 50%;
      bottom: -62px;
      background: #000;
      z-index: 1;
    }


    If you want to have an image or gradient as background with the transparency, use mask-image:

    body {
      background: pink;
    }
    
    .container {
      margin: 0 auto;
      width: 500px;
      height: 200px;
      -webkit-mask-image: radial-gradient(110% 50% at bottom, transparent 50%, #fff 51%);
              mask-image: radial-gradient(110% 50% at bottom, transparent 50%, #fff 51%);
      background: linear-gradient(45deg,red,yellow,blue);
    }

提交回复
热议问题