Search code examples
htmlcsscss-shapes

Is it possible to make this with CSS?


div with circle, encompassing the drop shadow

Is there a good way to make this with HTML/CSS? Basically a div, that has a circle "bump" on the edge. That part is easy using pseudo classes, but my problem is making the drop shadow treat it as part of the shape.

When I apply a drop shadow the circle separately, it doesn't work reliably. I know there's a way to do this..but I am unsure what the browser support is.

What would you guys recommend is the best way to tackle this? Thanks!


Solution

  • You can come close to this with a bunch of CSS. See this JSFiddle for a live example. However, there are disadvantages:

    • Bad support in IEs below 9
    • Not pixel-perfect, since some box-shadows overlap
    • The container must have position: relative (or absolute)

    The CSS:

    div {
        margin: 100px;
        width: 100px;
        height: 100px;
        box-shadow: 0 0 10px black;
        border-radius: 10px;
        position: relative;
    }
    
    div:before {
        display: block;
        content: "";
        width: 40px;
        height: 40px;
        position: absolute;
        left: -20px;
        top: 30px;
        border-radius: 20px;
        box-shadow: 0 0 10px black;
        clip: rect(-10px, 20px, 50px, -10px);
    }