I Have been googling for solutions to no avail. I just want to center-align
my canvas
.
I have tried float="center"
, text-align="center"
, margin-top: 100px
but my stage didnt align center in the browser.
Any help is appreciated.
<body onLoad="Main();">
<canvas id="Shooter" width="320" height="480" align="center">
Your browser does not support the HTML5 canvas tag.
</canvas>
You could center align it by:
#Shooter {
margin: auto;
display: block;
}
Make sure the parent container have 100% width.
Here's a pen. http://codepen.io/asim-coder/pen/aNpWoB
I suggest you remove the width
, height
and align
tags from canvas. Instead add a style region to your html and define a css-style for canvas:
<style>
canvas {
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
width: 320px;
height: 480px;
}
</style>
Your canvas would look like this:
<canvas id="Shooter">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With