I'm working on a project that needs to use CSS3 box-shadow property. That's fine, but I have found out that spread size of shadow can't be set to a percentage of parent object.
I fully understand that box-shadow is not additive, thus it doesn't take the size of a parent as a reference.
But given the fact that I need to have a fully responsive site with objects scaling fluidly (not only on breakpoints), but this also poses a problem – I can set shadow to spread property only in absolute units (em or px).
Is there any solution to this? I thought about using inner container (for content) within container (for "shadow" – it's without blur), but this creates another problem – vertical centering of inner container.
Any solution? No jQuery please, just pure CSS.
By using Scale we can change the size of the element based on its width and height ratio. Box shadow is used to create a drop shadow beneath the element. In the above code snippet, we have specified scale property that accepts the scale ratio as parameter. Accordingly it changes the height and width of the element.
The text-shadow property adds shadow to text. This property accepts a comma-separated list of shadows to be applied to the text.
The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations . Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color.
The offset-x and offset-y values are required for the CSS box-shadow property. The color value is not required, but since the default for the box-shadow is transparent, the box-shadow will not appear unless you specify a color value. The larger the blur-radius value, the bigger the blur.
I have found out that spread size of shadow can't be set to percentage of parent object
True. But you can set font-size
on the parent object, then define the object size in em
s, and use the same em
s to define the box-shadow
size.
Or, if your parent object happens to be the window, you can use viewport units: vw
and vh
.
If you're after an inset box-shadow
you could use a radial-gradient background to mimic the behaviour. So instead of -
box-shadow: inset 0 0 100% #000;
You would use -
background: radial-gradient(ellipse at center, rgba(0,0,0,0) 0,rgba(0,0,0,1) 100%);
Support: FF16+, IE10+, Safari 5.1+
I can't find any definitive answer on when Chrome started supporting the property, but my current version (39.0.2171.65) definitely supports it.
ColorZilla is a pretty useful tool for generating radial (among other) gradients along with the necessary prefixes if you decide to go down this route.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With