admin管理员组文章数量:1431037
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 / to see what I mean
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/qwertymk/TQSkX/ to see what I mean
Share Improve this question asked Dec 23, 2010 at 18:43 qwertymkqwertymk 35.4k30 gold badges124 silver badges184 bronze badges 2- You can't put a div inside a span. – Quentin Commented Dec 23, 2010 at 18:45
- Changing it to a div, didn't change anything. jsfiddle/qwertymk/TQSkX/2 – qwertymk Commented Dec 23, 2010 at 18:47
2 Answers
Reset to default 7z-index
does not apply to elements that are position: static
(which is the default)
You need to set the position on the second div in the css for it to read the z-index.
add position: relative;
to your second div and it should work fine.
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; position: relative; z-index: 2; ' +
'border: 1px solid black;">Inside div</div>';
document.body.appendChild(span);
本文标签: javascriptProblem with zindexStack Overflow
版权声明:本文标题:javascript - Problem with z-index - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745507523a2661313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论