----- JSBin Example ----
The answer is to use background-attachment
ORIGINAL QUESTION
I'm working on a project where we want to display a modal that "sees through" to the backdrop, but everywhere outside of the modal panel is slightly masked.
I have successfully used border: 10000px rgba(0,0,0,0.3)
with border-radius: 10010px
but this is a hack, and I can't outline the modal with a box-shadow
Is there any standard way for doing this? Bonus points if you can think of a way to apply a transparency filter gradient to an image.
I think the best option you got here is to have a 3-rows where the middle one contains 3 columns and the top-bottom rows & left-right columns (of the middle row) have darkened background:
The answer is to use
background-attachment
The best value would be
fixed
(not all devices support fixed) so that your backdrop and your modal can share the same viewportX
andY
(0, 0)
by defaultYou then scale with
background-size
percentages orcover
When using
background:
shorthand, make sure to use a/
to separatebackground-position
frombackground-scale
amountsI ran into a bug on an older device, so I used
local
then manually computedleftX
andtopY
to line up backdrop and modal-panelbackground-position
at(0, 0)
on my viewport.I then scaled both images with the same percentage, to cover the screen
I also used a gradient, credit -- How to darken a background Image