Reputation:
This is my sample. I set z-index of canvas as 0 and z-index of div as 1 but canvas is still higher than div, but if I set z-index of canvas as -1 it would work well. Could you tell me the reason?
<div id = 'all'>
<canvas style = "width:100px;height:100px; position: absolute;left: 10%;z-index:-1;background-color: yellow;"></canvas>
<div id = highscore style="width:100px;height:100px;z-index: 1;background-color: red;">
</div>
</div>
Upvotes: 2
Views: 3109
Reputation: 12969
z-index
Sets the stacking order of positioned elements, So it works only for positioned elements.
For Fix:
Insert
position: absolute;
tohighscore
Upvotes: 4
Reputation: 2224
z index only works when position is absolute
<div id='all'>
<canvas style="width:100px;height:100px; position: absolute;left: 10%;z-index:-1;background-color: yellow;"></canvas>
<div id="highscore" style="position: absolute;width:100px;height:100px;z-index: 1;background-color: red;"> </div>
</div>
Upvotes: 0