html - body d的background
PHP中文网
PHP中文网 2017-04-17 13:43:02
[HTML讨论组]

body 设置了background-color 也设置了margin:10px 但是页面外边框处依然能显示背景颜色

background-color 不是应该在包裹在 margin里面么?

小弟刚学CSS 问题比较蠢 请各位大神不惜批评指正

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(2)
巴扎黑

刚看到这个问题,以为是你哪里设置有问题,用jsfiddler复现了,立刻意识到这个问题有一定价值。

所以,我查看了文档后,找到了这么一段话。

For documents whose root element is an HTML HTML element [HTML401] or an XHTML html element [XHTML11]: if the computed value of ‘background-image’ on the root element is ‘none’ and its ‘background-color’ is ‘transparent’, user agents must instead propagate the computed values of the background properties from that element's first HTML BODY or XHTML body child element. The used values of that BODY element's background properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the BODY element rather than the HTML element.

参考:The Canvas Background and the HTML <body> Element

简单来说,如果html元素的background-image是none,并且background-color是transparent(当然这个是默认值)。UA应该从他的body子元素中借用属性来styling。也就是说,它应该满足两个条件。

所以只要任意一个不符合,浏览器就不会扩大绘制区域了。

DEMO

望采纳!

伊谢尔伦

body是可以添加margin,padding属性,设置margin,padding的展示效果没有差异,原理上一个是外边距,一个是内边距,其中子元素对于该值没有影响,即浏览器不会出现滚动条

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号