Not quite. The problem here is that you're putting the overlay in the body and the dialog can be anywhere, even in a different stacking context. Z-index values are relative values, not absolute values, so you can't do z-index math in a different context. The overlay would have to be in the same stacking context and that's going to make your positioning break.