2012-11-13 46 views
3

我有一个尺寸为1620 * 1080的背景图像,我的屏幕分辨率是1366 * 768。它怎么可能不包括我屏幕的15%左右(右边部分)?背景图像不包括整个屏幕

这里是我的代码:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<style type="text/css"> 
body { 
    min-height: 100%; 
    min-width: 100%; 
    background-image:url(background.png); 
    background-repeat: no-repeat; 
} 

div#container { 
    margin: 0 auto; 
    background-color: red; 

} 
</style> 
</head> 
<div id="container"> 

</div> 
<body> 
</body> 
</html> 

正如你可以看到我已经添加

min-height: 100%; 
min-width: 100%; 

想,也许这将有助于。而background-repeat: no-repeat;只是因为它不覆盖屏幕。

任何想法?谢谢!

+1

为什么你身上的标签之外一个div? – stark

+0

副本错误... – Yotam

回答

6

试试这个:

body { 
    background: url(background.png) no-repeat center center fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
} 

这会给你一个全尺寸的背景图像窗口是否比你的图像放大或缩小。

如果不行,请阅读this css-tricks post的其余部分。

4

您的图片比例为1620/1080=1.5,,屏幕分辨率为1366/768=1.77。基本上,所发生的是图像以较小的尺寸显示,同时保持按比例绘制。右侧的区域被封锁。

尽量只张贴大小

background-size:100% 100%; 
+0

谢谢!那真的有助于 – Yotam

+1

@Yotam,如果Pearson的回答帮助了你,那么将其标记为已接受! – crowjonah