2013-02-26 88 views

回答

-2

使用純CSS。

嘗試

Canvas { 

    Width: 300px; 
    Margin: 0 auto; 
    Vertical-align: middle; 

} 
-1

如果我理解你的問題的權利,你可以把:

#myCanvas { 
    border: 1px solid #9C9898; 
    background-color:#CFF; 
    position:absolute; 
    left:100px; // go messing with the value until it's centered. 
} 

#myCanvas { 
    border: 1px solid #9C9898; 
    background-color:#CFF; 
    position:center; 
} 

希望這有助於!

-1

使用CSS。嘗試,

canvas { 

    border: 1px solid #000000; 
    position:  relative; 
    left:    500px; (Play with this # to position horizontally) 
} 
-1

//Canvas stuff 
 
\t var canvas = document.getElementById("canvas"); 
 
\t var ctx = canvas.getContext("2d"); 
 
\t ctx.fillStyle = "black"; 
 
\t ctx.fillRect(0, 0, 30, 30);
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<style> 
 

 
</style> 
 
</head> 
 
<body> 
 
    <canvas id= "canvas" width=30px; height=30px; style='display: block;margin: auto;' ></canvas> 
 
</body> 
 
</html>