以下是 html5背景图片自适应代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>html5背景图片自适应代码</title>
<link href="css/zzsc.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- 代码 开始 -->
<section id="h1" class="jawbone-takeover-minimulti jawbone-hero"><i class="jawbone-hero-image" data-hero-image-fixed="true" data-hero-image-fade="true" data-hero-min-opacity=".3" style="opacity: 1.05;"></i></section>
<!-- 代码 结束 -->
</body>
</html>
CSS代码(zzsc.css):
.jawbone-hero .jawbone-hero-image{position:absolute;background:transparent none no-repeat scroll 50% 0;background-size:cover;top:0;bottom:0;left:0;right:0;width:100%;margin:0 auto;z-index:-1}
.jawbone-hero{height:100%;min-height:550px}
.jawbone-hero .jawbone-hero-image{position:fixed}
#h1.jawbone-takeover-minimulti .jawbone-hero-image{background-image:url(../images/hero-600.jpg)}
@media (min-width:600px){#h1.jawbone-takeover-minimulti .jawbone-hero-image{background-image:url(../images/hero-1280.jpg)}
}
@media (min-width:1016px){#h1.jawbone-takeover-minimulti .jawbone-hero-image{background-image:url(../images/hero-2000.jpg)}