I think the only way to infer div from all parent div is by absolute positioning for all of them, which will obviously create its own set of problems.
Why not just have a predefined hidden div as a direct child of the body, and not wrap it in markup. Then you can easily place it the way you want and insert error messages into it using jQuery . The obvious advantage of this method is that you only need to write this div once and dynamically insert the error message into it. I would even suggest taking a look at the jQuery UI , which allows you to easily create dialogs, both regular and modal, besides a ton of other functions.
UPDATE
Since JS is not allowed, an easy way to do this is to actually display the div only in case of an error. So the PHP code will be ...
if (isset($error)) { echo '<div class="show_error">' . $error . '</div>'; }
... and the CSS class for it will be ...
.show_error { width: 400px; // error element width height: 200px; // error element height position: absolute; top: 50%; left: 50%; margin-top: -100px; // minus half the height margin-left: -200px; // minus half the width }
Of course, you can optionally format the div as you want, but this is necessary to place the dead center.
Hope this helps!
Valentin flachsel
source share