无法居中对齐画布

her*_*cat 4 html canvas center alignment

我一直在谷歌搜索解决方案无济于事.我只想要center-align我的canvas.我已经试过float="center",text-align="center",margin-top: 100px 但在浏览器中我的舞台didnt居中.任何帮助表示赞赏.

<body onLoad="Main();">
<canvas id="Shooter" width="320" height="480" align="center">
Your browser does not support the HTML5 canvas tag.
</canvas>
Run Code Online (Sandbox Code Playgroud)

Asi*_*K T 6

您可以通过以下方式对齐它:

#Shooter {
  margin: auto;
  display: block;
}
Run Code Online (Sandbox Code Playgroud)

确保父容器的宽度为100%.

这是一支钢笔. http://codepen.io/asim-coder/pen/aNpWoB