2014-03-19 42 views
0

在HTML中,我嘗試創建一個只顯示黑色圖像的畫布,另一個畫布在黑色畫布上顯示白色邊框在它下面。下面是HTML代碼:使用z-index分層多個畫布不顯示最高層

<body> 
<canvas width=600 height=400 style="position:absolute;background-image:url('Black.png');z-index:1;" 
</canvas> 
<canvas width=400 height=200 style="position:absolute;border:1px solid #FFFFFF;z-index:2;" 
</canvas> 
</body> 

當我運行谷歌瀏覽器的代碼,我只能看到黑色背景,無白邊。我在這裏做錯了什麼?我試圖尋找問題,但我沒有找到答案。

回答

1

你關閉你的畫布標記?

你有

<canvas width=600 height=400 style="position:absolute;background-image:url('Black.png');z-index:1;" 

嘗試,而不是

<canvas width=600 height=400 style="position:absolute;background-image:url('Black.png');z-index:1;"> 
2

這是因爲您的HTML格式不正確。

此:

<canvas width=600 height=400 style="position:absolute;background-image:url('Black.png');z-index:1;" 

應該是這樣的:

<canvas width=600 height=400 style="position:absolute;background-image:url('Black.png');z-index:1;">