html - body d的background

查看:104
本文介绍了html - body d的background的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

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

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

解决方案

刚看到这个问题,以为是你哪里设置有问题,用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

望采纳!

这篇关于html - body d的background的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆