Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 775
Andrew Parisi Avatar asked Apr 12 '13 13:04

Andrew Parisi


2 Answers

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);
}
like image 149
Boldewyn Avatar answered Oct 01 '22 12:10

Boldewyn


To be honest, an image, if you want it to make it work on mozilla, safari and chrome. It can be done with css3 but I wont recommend it.

like image 38
DiederikEEn Avatar answered Oct 01 '22 11:10

DiederikEEn