我有一个 html 文档,我想在其中使用图像作为背景。对于下一个示例,一切都很好:
<html><head></head><body><div id="principal"></div></body></html>
CSS:
#principal
{
background: url(../Img/org/world.png) no-repeat;
width:100%;
height:100%;
background-size: 100% 100%;
}
但是如果我将 html 文件重写为:
<!DOCTYPE html><html><head></head><body><div id="principal"></div></body></html>
来自 css ( background: url(../Img/org/world.png) no-repeat; ) 的图像不再显示。为什么?
最佳答案
将此添加到您的样式表:
html,body {width:100%;height:100%;}
您设置为 100% 的 DIV 没有任何引用它应该设置为 100% 的内容。告诉浏览器文档将填充 100% 的可用内容,为 div 元素创建一个引用。
摆弄的 fiddle :
http://jsfiddle.net/UJsRW/
关于html - DOCTYPE 声明删除了我的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14172174/