Skip to content Skip to sidebar Skip to footer

How To Overlay A Div Over A Canvas CSS

I'm trying to place a div over a canvas in HTML5 (as a HUD of sorts). I'm using z-index, it's not working. How can I achieve this using any CSS? .HUD { z-index:100;

Solution 1:

Try this:

#container {
  position: relative;
}
#container canvas, #overlay {
  position: absolute;
}
canvas {
  border: 1px solid black;
}
<div id="container">
  <canvas></canvas>
  <div id="overlay">This div is over the canvas</div>
</div>

We wrap the canvas and div in a container element, which is position: relative. Then the canvas and div are set to position: absolute.


Solution 2:

try something like this

<div class="container_div" style="position:relative;">
    <div class="hover_div" style="position:absolute; width:25px !important; display:block;z-index:9999">                            
        <img class="some_class" src="/settings_icon.png" style="height: 20px; display: block;">
    </div>
<canvas width="180" height="270" style="width: 180px; height: 270px;"></canvas>
</div>

Post a Comment for "How To Overlay A Div Over A Canvas CSS"