0005. canvas 的默认尺寸 300 x 150
1. 📝 简介
- 知道
<canvas>
默认是 300x150 的行盒。
2. 📒 notes
如果你仅仅创建了一个 canvas,但是并没有指定它的 width、height,那么这个 canvas 的默认尺寸是 300x150。
3. 💻 demo
html
<!-- 1.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
canvas {
outline: 1px solid #ddd;
}
</style>
</head>
<body>
<!--
1. canvas 是一个行内元素
2. canvas 默认大小是 300 * 150
打开浏览器查看最终渲染效果会发现俩盒子同行显示。
打开 devtools,查看盒模型,会发现盒子尺寸是 300 * 150。
-->
<canvas></canvas>
<canvas></canvas>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
最终的渲染结果
从最终的渲染结果(并行显示)来看,会发现其实 canvas 并非块盒。
计算属性及盒模型