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-index else auto,
    • and additionally position either relative, absolute or fixed.
  • 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! -->         &nbsp;     </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! -->         &nbsp;     </div>     <div>         <div id="widgetthatcausesthepopup" style="position: absolute; z-index: 1;">             <button>show popup</button>         </div>     </div> </div> 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -