Search code examples
javascriptcssz-indexinline-styles

Problem with z-index


I must be missing something about z-index. Look at this code:

var span = document.createElement('span');
span.innerHTML = '<div style="background: none repeat scroll 0px 0px' +
    '#000000; opacity: 0.7; display: block; top: 0px; bottom: 0px; ' +
    'left: 0px; right: 0px; position: fixed; z-index: 1;"></div>';

span.innerHTML += '<div id="fancybox-wrap" style="opacity: 1; ' +
    'width: 420px; height: 200px; top: 467px; left: 481.5px; ' +
    'display: block; z-index: 2; ' +
    'border: 1px solid black;">Inside div</div>';
document.body.appendChild(span);

Based on the fact that the second div has a higher z-index, should it be on top of the first div?

Take a look at http://jsfiddle.net/qwertymk/TQSkX/ to see what I mean


Solution

  • z-index does not apply to elements that are position: static (which is the default)