首页 > 为什么结果会向下移了10px

为什么结果会向下移了10px

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>practice</title>
<style>

body{background:black}
#cvs{background:white}

</style>
<script>
window.onload=function(){

var oCvs=document.getElementById("cvs");
var oGc=oCvs.getContext("2d");  
oGc.font="60px impact";
oGc.textBaseline="top";
oGc.fillText("妙味课堂",0,0);    

}
</script>
</head>
<body>

<canvas id="cvs" width="400px" height="400px"></canvas>

</body>
</html>


oGc.textBaseline="hanging";


css rester没有写


你是指这个 canvas#cvs 距离顶部有空隙吗?
如果是这个意思,那么是因为 body 有默认的样式:

body {
    display: block;
    margin: 8px;
}

RESET 掉就可以了

【热门文章】
【热门文章】