前端学习之背景图错位 发表于 2016-01-29 | 分类于 前端 | 前端学习之背景图错位 现象现象如下图:这里的想法是不将背景图片放到body上,而是body充满屏幕,div(这个div作为整个内容容器)充满body,然后div背景图充满div。 分析代码12345678910111213141516171819202122232425262728293031323334353637383940414243<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>csstest</title> <style> html{ height:100%; } body{ background-color: red; height: 100%; margin: 0px; padding: 0px; overflow: hidden; } #container{ background: url(image/dota2Index.jpg); background-size: cover; background-repeat: no-repeat; color: white; height: 100%; font-size: xx-large; padding: 0px; margin: 0px; width: 100%; /* position: absolute; top: 0; left: 0;*/ } #container p{ text-align: center; } </style></head><body> <div id="container"> <p id="welcomeWord"> welcome to dota2</p> </div></body></html> **解决方法将稳重注释掉的地方恢复。