2013-02-06 128 views
0

我想,所以我用下面的代码全屏背景HTML

HTML显示图片作为我的网站的背景:

<div> 
    <img src="images/background.jpg" id="bg" alt="background_image" /> 
</div> 

的CSS:

#bg { 
    width: 100%; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 
} 

我想知道如何限制背景的大小,因为我不想伸展超过2000像素。

感谢

+0

背景大小是一个选项使用。 详情请参阅http://www.css3.info/preview/background-size/ – lukeocom

回答

1

只需在您的CSS最大宽度。

#bg { 
    width: 100%; 
    max-width: 2000px; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 
} 
0

您可以使用max-width

#bg { 
    width: 100%; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 

    max-width: 2000px; /* use this to limit the maximum width */ 
} 
1

我会用下面的CSS:

html { 
    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; 
} 

和完全删除您的股利。

要限制大小,您可以:

#bg { 
    min-height: 100%; 
    max-width: 2000px; 
    width: 100%; 
    height: auto; 
    position: fixed; 
    top: 0; 
    bottom: 0; 
} 
0

我没有测试过,但增加max-width:2000px;您#bg选择。

0

试试这个

#bg { 
width: 100%; 
height: 100%%; 
background-size:100%; 
}