html - Relative z-index? -
i've got "dialog" widget pops z-index of 100. when create popup (a floating div), appears underneath dialog widget, because haven't explicitly set z-index on new popup.
the structure ends looking like
<div id="dialogbox" style="z-index: 100"> <div> <div id="widgetthatcausesthepopup" /> </div> </div> <div id="popuphiddenbehindthedialog" /> i'm using gwt generate html. there can arbitrary levels of nesting between dialogbox , widgetthatcausesthepopup, , actual z-index may arbitrary well.
how can ensure new div shown in front of dialogbox?
the natural css solution to:
- make sure, "dialogbox" gets stacking context. can done
- setting
z-indexelseauto, - and additionally
positioneitherrelative,absoluteorfixed.
- setting
- then add popup child "dialogbox". if isn't yet, can move in dom.
in case, popup doesn't need z-index @ all. avoids "z-index hell".
example:
<!doctype html> <html> <head> <style type="text/css"> #dialogbox { width: 400px; height: 300px; top: 0; left: 0; background-color: red; } #popup { width: 500px; height: 200px; top: 0; left: 0; background-color: green; } </style> </head> <body> <div id="dialogbox" style="z-index: 100; position: absolute;"> <div> <div id="widgetthatcausesthepopup" > <button>show popup</button> </div> </div> <div id="popup" style="position: absolute;"> <!-- empty divs cause weird problems. make sure, divs aren't empty! --> </div> </div> </body> </html> the stacking context allows use z-indexes relative context, if need them (note, child order doesn't matter, , z-indexes don't have larger 100):
<div id="dialogbox" style="z-index: 100; position: absolute;"> <div id="popup" style="position: absolute; z-index: 2;"> <!-- empty divs cause weird problems. make sure, divs aren't empty! --> </div> <div> <div id="widgetthatcausesthepopup" style="position: absolute; z-index: 1;"> <button>show popup</button> </div> </div> </div>
Comments
Post a Comment