Experimenting with the CSS3 box-shadow property, I was wondering if you could prevent the object casting it to clip the shadow. In the following code the DIV casting the shadow is invisible, but the shadow is clipped nonetheless. Is there a way to get this done in CSS? Also maybe in JavaScript / JQuery? Or is the only way to set the box-shadow offset larger than the DIV, and reposition the shadow (not very elegant).
div#shadow
{
position: absolute;
background-color: transparent;
top: 100px;
left: 100px;
width: 300px;
height: 200px;
box-shadow: 100px 100px 100px gray;
}
I am not a fan of position elements off the page, but that might be a good way of doing it?
Give the
leftproperty a large negative value, then give thebox-shadow‘s left property a figure calculated using this formula:So for your example above, it would be:
You can see it working in this jsfiddle.
The only other way I could see would be to match the
border-radiusandbackground-colourof thedivso that it matched the shadow. Theborder-radiuswould be100pxin this case, but I couldn’t match thebackground-colorat all and off course it would change with different colours or images.