我目前正在一個我需要心的網站上工作。我創建一個使用JavaScript和CSS的心:z-index屬性的行爲並不像預期的那樣
function heart(x, y, pos, width, r) {
var height = width + (width/2 + 1);
var heart = "position:" + pos + ";left:" + x + "px;top:" + y + "px;width:" + width + "px;height:" + height + "px;transform: rotate(" + r + "deg);-moz-transform: rotate(" + r + "deg);-webkit-transform: rotate(" + r + "deg);";
var slices = "left:" + width + "px;width:" + width + "px;height:" + height + "px";
$("body").append('<div class="heart" style="' + heart + '"><div class="slice" style="' + slices + '"></div><div class="slice2" style="' + slices + '"></div></div>');
}
我目前正在嘗試使用到放一個大心臟下一個框:
heart(282, 69, "absolute", 230, 0);
然而,z-index
沒有做任何事情,你可以看到在我的JSFiddle例子中。
我甚至試圖將通用選擇器(*)的z-index
設置爲0,同時將框的z-index
更改爲10 !important;
,但這也不起作用。我對這種情況發生的原因感到困惑,但我很確定它與動態心臟有關。謝謝。
+1快速回答+ z-index:-1'解決方案c: – Shawn31313
它不需要*被絕對定位。相對定位可能更實際,在這種情況下就足夠了。當然,無論是工作,它只是需要一些'靜態'旁邊的東西.. –
它需要位置相對,不是絕對有效 – Pinki