我想让背景图片覆盖整个页面,但到目前为止我只有这个:
这是我想要覆盖浏览器窗口的图片:
我的外部CSS包含以下代码:
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("mybackground.jpg")}
有人能告诉我如何编辑CSS文件以解决我的问题吗?
另一个选项也可以包括:
body{
background-image:url("mybackground.jpg")
background-size:contain;
background-repeat:no-repeat;
}
body {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
请查看以下链接获取更多信息: http://css-tricks.com/perfect-full-page-background-image/
background-size: 10px 10px
将 body 的宽度和高度改为 10
你也可以这样做
background-size: 100%
background-size: 100%
。 - JMGbackground-size: 100%
的结果:http://jsfiddle.net/6TT2v/ 如果图片的宽高比与页面相同,那么就很好,否则... - FelipeAlsbackground-repeat: no-repeat
...问题是什么? - JMG你需要将它变成一个 <img>
标签,并设置一个低的 z-index
,使用 position: fixed
,然后为 <img>
标签使用 height: 100%; width: auto
或相反。
这种方法适用于所有浏览器。