html - Fixed position overlap absolute position? -


i try create modal i'm stuck in getting overlay layer done.

demo http://jsfiddle.net/4z3fss9t/

.modal-wrap{       display: block;   opacity: 1;   position: absolute;   top: 20%;   padding: 0 40px;   left: 0;   border: none;   right: 0;   z-index: 9999; }  .modal-content{ background-color: white;   padding: 10px; }  .modal-overlay{       position: fixed;   background: black;   width: 100%;   height: 100%;   left: 0;   top: 0;   opacity: 0.5; } 
<div class="modal-wrap">      <div class="modal-content"> content goes here </div>      <div class="modal-overlay"></div> </div>  

i expect position absolute come in front z-index don't, idea?

honestly, whole idea behind z-index in css confuses web designers. it's not rocket science, favor understanding core concepts behind what's happening. odd behaviors fighting with, seem less voodoo.

positioned elements

first of all, non-positioned elements not affected z-index. herein lies first problem, since (as noted abdul in answer) modal content not have position directive in css.

understanding css' z-index directive

here excerpt excellent article philip walton:

stacking order

z-index seems simple: elements higher z-index stacked in front of elements lower z-index, right? well, actually, no. part of problem z-index. appears simple, so developers don’t take time read rules.

every element in html document can either in front of or behind every other element in document. known stacking order. rules determine order pretty defined in spec, i’ve stated, they’re not understood developers.

when z-index , position properties aren’t involved, rules pretty simple: basically, stacking order same order of appearance in html. (ok, it’s little more complicated that, long you’re not using negative margins overlap inline elements, won’t encounter edge cases.)

when introduce position property mix, positioned elements (and children) displayed in front of non-positioned elements. (to element “positioned” means has position value other static, e.g., relative, absolute, etc.)

finally, when z-index involved, things little trickier. @ first it’s natural assume elements higher z-index values in front of elements lower z-index values, , element z-index in front of element without z-index, it’s not simple. first of all, z-index works on positioned elements. if try set z-index on element no position specified, nothing. secondly, z-index values can create stacking contexts, , seemed simple got lot more complicated.

conclusion

finally, if dive deep, there great resources z-index on mozilla developers network

  1. https://developer.mozilla.org/en-us/docs/web/css/z-index
  2. https://developer.mozilla.org/en-us/docs/web/guide/css/understanding_z_index

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -