html – 为什么造型body元素的背景会影响整个屏幕?

当您设计body元素的背景时,为什么样式会影响整个屏幕,而不仅仅是body元素本身?假设我创建了以下规则:
body {width: 700px; border: 1px dotted red; background-color: blue;}

我发现边框显示为700px宽,如我所料,但背景颜色占据整个浏览器视口.为什么?

解决方法

报价从 http://www.w3.org/TR/CSS21/colors.html

The background of the root element becomes the background of the canvas and covers the entire canvas,anchored (for ‘background-position’) at the same point as it would be if it was painted only for the root element itself. The root element does not paint this background again.

body元素是根元素,因此,根据CSS规则的要求,它将丢失其背景样式,并将背景样式应用于包含画布(浏览器中的网页区域),因此整个屏幕是蓝色的.其他属性与元素(例如边框)保持一致.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些