How to give a div oval shape?

前端 未结 5 911
粉色の甜心
粉色の甜心 2020-12-03 18:17

I tried a lot on oval shape which have cut in both sides but not able to do it please \"enter<

5条回答
  •  猫巷女王i
    2020-12-03 18:44

    Here are two possible variants:

    Method #01:

    Use radial-gradient():

    background: radial-gradient(ellipse 65% 40%, transparent 0, transparent 90%, black 90%);
    

    body {
      background: linear-gradient(orange, red);
      padding: 0 20px;
      margin: 0;
    }
    .oval {
      background: radial-gradient(ellipse 65% 40%, transparent 0, transparent 90%, black 90%);
      height: 100vh;
    }

    Method #02:

    1. Create an overlay with :before or :after pseudo element.
    2. Add border-radius.
    3. Apply a large box-shadow with overflow: hidden on parent to hide undesired area.

    body {
      background: linear-gradient(orange, red);
      padding: 0 20px;
      margin: 0;
    }
    .oval {
      position: relative;
      overflow: hidden;
      height: 100vh;
    }
    
    .oval:before {
      box-shadow: 0 0 0 500px #000;
      border-radius: 100%;
      position: absolute;
      content: '';
      right: -10%;
      left: -10%;
      top: 10%;
      bottom: 10%;
    }

提交回复
热议问题