Search code examples
htmlcssgradientshapescss-shapes

CSS Square Div with an Inward Oval Shape


I am trying to create a div in css with an inward oval shape to it like this.

At the moment, I have a shape that is outward instead of inward (JS Fiddle Link).

.shape {
float: left;
width: 100px;
height: 50px;
border: none;
background: #CC0000;
border-radius: 0 90px 0 0;
-moz-border-radius: 0 90px 0 0;
-webkit-border-radius: 0 90px 0 0;
background-image: -webkit-gradient( linear, left top, right bottom, color-stop(0, #520C0C), color-stop(1, #CC0000) );
background-image: -o-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -moz-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -webkit-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: -ms-linear-gradient(right bottom, #520C0C 0%, #CC0000 100%);
background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
}

Any ideas on how to go about this?


Solution

  • Have a look at my example fiddle.

    I used a pseudo-element and some elliptical border-radius coupled with an inset box-shadow.

    div {
        position:relative;
        width: 200px;height: 100px;
        background: #CC0000;
        background-image: linear-gradient(to right bottom, #520C0C 0%, #CC0000 100%);
    }
    div:after {
        position:absolute;content:"";
        width: 100%;height: 95%;
        background: #222;
        box-shadow:inset 10px -10px 5px -10px #000;
        border-radius: 0 0 0 200px / 100px;
    }
    

    With a little more effort, one could probably get closer to your result, but this might be a good starting point.