Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In html 5, how to positioning a div element on top of a canvas element?

Tags:

html

css

Can anyone help me: I'm trying to put a div (say, 10px by 10px) element on top (in front) of a canvas element (say 500px by 500px) in html. I have tried changing the z-index of each, to no avail. Does anybody have any ideas, or is it one of those things that you can't really do? I already know how to do absolute positioning and everything, the div element just hangs out in the background behind the canvas element. I need a way to bring it to the front and the canvas element to the back.

Thanks!

like image 437
Unraised Avatar asked Apr 20 '10 00:04

Unraised


1 Answers

The way absolute positioning works is that, in general, elements that are earlier in the code are behind elements that are later in the code. To change that you do indeed use z-index. Note, though, that z-index only works on elements that are positioned.

Another thing that may be tripping you up is that all positioned elements act like z-index "containers". So if your <div> happens to be earlier in the document and in another positioned container, it may be bound to the z-index layer of its ancestor, and so can't ever escape and display on top of the <canvas>. If this is the case, you'll either have to slightly rewrite your CSS or rearrange your page so that the <div> is in a good spot.

like image 162
Xanthir Avatar answered Sep 19 '22 23:09

Xanthir