I’m trying to figure out if this is possible with css. I want a square that has a drop shadow. At the bottom of the square, the drop shadow is completely visible. At the top of the square, no drop shadow should be apparent. This would be a gradient so being in between the top and bottom, the drop shadow would be half visible.
Any ideas on how to achieve this?
It is possible to emulate that using a gradient on an absolutely positioned pseudo-element, with a
z-indexsuch that it appears underneath its parent element.HTML:
CSS:
If you want the shadow to have a faded edge, then you’ll have to give the pseudo-element an inset shadow (same colour as the background of
.e‘s parent).Note that this won’t work in IE9 and older. You can use
filtergradients for those, but not on pseudo-elements, so what you would have to do in this case would be to add a child to the element (just for IE) and style it just like you style the pseudo-element.EDIT: If you want this to work over an image, gradient background, then I’m afraid it’s a bit trickier and it cannot be done using just CSS in IE9 and older. However, in the current versions of the other browsers, this can be achieved using a linear gradient and three radial gradients.
Relevant CSS: