0

如何将画布居中(水平和垂直)?我想以此为中心:http: //invisiblelabs.net/ex4.html

4

1 回答 1

0

在 head 标签中添加:

<style type="text/css">
#box {
height:400px;
width:200px;
background:#FFF;
position:absolute;
left:50%;
top:50%;
margin:-150px 0 0 -250px;
}

.thecanvas {
height:200px;
width:100px;
background:#FFF;
position:absolute;
}
</style>

并将其替换为您当前的画布元素:

<div id="box">
<canvas id="thecanvas" width="400" height="200">
    Your browser does not support the HTML5 canvas element.
</canvas>
</div>  

我为我工作,我希望它也适合你。

于 2013-08-19T14:17:21.897 回答