当您设计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规则的要求,它将丢失其背景样式,并将背景样式应用于包含画布(浏览器中的网页区域),因此整个屏幕是蓝色的.其他属性与元素(例如边框)保持一致.
原文地址:https://www.jb51.cc/html/231360.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。