我不知道为什么这个css工作时我在body标签设置为100%高度时使用背景图像但是当我在div上使用它时它没有显示全高(仅显示屏幕高度) 这是代码: body div id="bg" /div/body CSS body{position:rela
这是代码:
<body> <div id="bg"> </div> </body>
CSS
body{ position:relative; padding: 0; overflow-x: hidden; font-family: "Titillium Web"; color:#fff; width: 100%; } #bg{ height:100%; background-color: #030000; background-image: url(img/bg.jpg); background-repeat: no-repeat; background-position: top center; background-size: 100% auto; }
我不想使用背景尺寸:请盖好
设置正文和html高度:100%body,html{ height: 100%; margin:0; } body{ position:relative; padding: 0; font-family: "Titillium Web"; color:#fff; width: 100%; } #bg{ height:100%; background-color: #030000; background-image: url(img/bg.jpg); background-repeat: no-repeat; background-position: top center; background-size: 100% auto; }
DEMO HERE
如果你想要全身做这个:
body,html{ height: 100%; margin:0; } body{ position:relative; padding: 0; font-family: "Titillium Web"; color:#fff; width: 100%; background-color: #030000; background-image: url(http://www.abelabad.com/abad/img/bg.jpg); background-repeat: no-repeat; background-position: top center; background-size: 100% auto; background-attachment: fixed } #bg{ height:100%; }
DEMO HERE