[英]Strange behavior with dimensions of canvas
So, I'm confused about a current problem, which thankfully is easy to demonstrate to you guys. 所以,我对当前的问题感到困惑,幸好很容易向你们展示。
Here it is on JSFiddle: 这是JSFiddle:
Using the canvas : upper.height=$(document.body).height() - lower.height();
使用画布 :
upper.height=$(document.body).height() - lower.height();
Using a substitute div : upper.height($(document.body).height() - lower.height());
使用替换div :
upper.height($(document.body).height() - lower.height());
As you can see, a small margin of a few pixels is placed after the canvas for some reason. 正如您所看到的,由于某种原因,在画布之后放置了几个像素的小边距。 It ends up creating a scrollbar, since it becomes 4 pixels taller than the viewport it's trying to fill.
它最终会创建一个滚动条,因为它比它试图填充的视口高4像素。 Why is this?
为什么是这样? I've set
margin:0;
我设定
margin:0;
and padding:0;
和
padding:0;
for all elements. 对于所有元素。
Thanks so much! 非常感谢!
You need to set the canvas
as a block element (a div
is block level by default), it is inline by default which is why you are seeing the variation in behaviour: 您需要将
canvas
设置为块元素(默认情况下div
是块级别),默认情况下它是内联的,这就是您看到行为变化的原因:
canvas{
display:block
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.