我有這兩個 div,并且打算將“a”保持在 z-index 設置的“b”上方,但它不起作用,并且日志顯示兩個 z-index 都是自動的。為什么?<div id="a" style="z-index=2; position:fixed; width:100%; height:40px; background:green;"></div><div id="b" style="z-index=1; position: relative; width:100%; top:20px; height:100px; background:gray; left:40px;"></div> <script>console.log("a",window.getComputedStyle(document.getElementById("a")).zIndex);console.log("b",window.getComputedStyle(document.getElementById("b")).zIndex);</script>如果通過 javascript 設置它可以工作:document.getElementById("a").style.zIndex=2;但是 z-index set inline 不起作用,為什么?
添加回答
舉報
0/150
提交
取消