使用CSS

时间:2015-06-01 22:24:00

标签: html css

我有一个我想要的图像占据整个屏幕,但在屏幕的顶部和左侧留下一些空白区域,我不知道为什么要这样做。我附上了它的代码。

img {
background: 0px 0px / 100% 100% no-repeat scroll rgb(12, 12, 12);
height: 100%;
width: 100%;
position: fixed;
}
<img src="http://www.morefree.net/wp-content/uploads/2013/03/black-wallpaper-01.jpg">

3 个答案:

答案 0 :(得分:4)

添加此css行:

body{margin:0;}

http://jsfiddle.net/mm08hruf/

答案 1 :(得分:3)

您需要重置身体上的边距。

&#13;
&#13;
/* margin reset */
body {
  margin: 0px;
}

img {
  background: 0px 0px / 100% 100% no-repeat scroll rgb(12, 12, 12);
  height: 100%;
  width: 100%;
  position: fixed;
}
&#13;
<img src="http://www.morefree.net/wp-content/uploads/2013/03/black-wallpaper-01.jpg">
&#13;
&#13;
&#13;

答案 2 :(得分:1)

尝试

html,body{
   padding:0;
   margin:0;
}