I am trying to place a div element above the canvas (this is for the game) in the center of my page. This is a start screen, which I want to show on top of the canvas, before starting the game (this start screen has options such as "Play the game", "Settings", etc.). The problem is that I cannot do this, I searched a lot on Google, I saw a lot of examples, but none of them seem to work for me. Here is my code:
<div id="gamecontainer"> <canvas id="myCanvas" width="800" height="600"> Sorry, <strong>CANVAS</strong> is not supported by your browser. Get a more recent one to play my game! </canvas> <div id="gamestartscreen" class="gamelayer"> <img src="images/icons/play.png" alt="Play Game" onclick="alert('ceve');"><br> <img src="images/icons/settings.png" alt="Settings"> </div> </div>
here is the css:
#gamecontainer { width: 800px; height: 600px; background-color: beige; border: 1px solid black; position: relative; margin: 0 auto; } .gamelayer { width: 800px; height: 600px; position: absolute; display: none; z-index: 0; } #gamestartscreen { position: relative; margin: 0 auto; } #gamestartscreen img { margin: 10px; cursor: pointer; }
Can someone please tell me where I am doing this wrong?
css html5 center canvas
AndrΓ© hincu
source share