HTML / CSS DIV和背景图像 [英] HTML/CSS Div and Background Image

查看:154
本文介绍了HTML / CSS DIV和背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的图像。我想用这个形象,我的网站的背景。我也想为这个图像伸展和适应不同的浏览器窗口大小。

I have a very large image. I want to use this image as the background of my website. I would also like for this image to stretch and fit different browser window sizes.

这是解决方案,我想出了。 (我把它放在jFiddle,使其更容易为你们阅读)。

This is the solution I have come up with. (I put it on jFiddle to make it easier for you guys to read).

http://jsfiddle.net/sGyax/

.bg{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -5000;}

<body>
<div id="background">
    <img src="background/001.JPG" class="bg"/>
</div>
</body>

反正对我来说,做到这一点没有在我使用的HTML IMG标记?它干扰了我的布局的其余部分。

Is there anyway for me to do this without using IMG tag in my HTML? It interferes with the rest of my layout.

推荐答案

本应在IE9 / 10和当前的Firefox,Opera和Chrome浏览器:

This should work in IE9/10 and current Firefox, Opera and Chrome:

html{
    background: url(background/001.JPG) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='background/001.JPG',     sizingMethod='scale');
    -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='background/001.JPG', sizingMethod='scale');
}

这篇关于HTML / CSS DIV和背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆