html5图片高度自适应解决方法

今天遇到一个HTML5图片高度自适应各个设备问题,网上找到一个解决方法,跟大家分享下。

由于<body>标签的图片不能够拉伸,

解决办法:

1、图片不够大,又background属性不能拉伸图片;

2、只能用个div,把其z-index值设为负,并使这个div大小为整个body大小,在div里用<img>

3、body的background属性去掉,要不然会被遮住。

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>Hello World</title>
<meta content="width=640, target-densitydpi=320, user-scalable=no" name="viewport" /> 
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
</head>    
<body>    
<div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">    
<img src="pictures/background.jpg" height="100%" width="100%"/>    
</div>    
</body>    
</html>  

——非原创,摘自CSDN。

posted @ 2014-10-16 16:29  Fien  阅读(2802)  评论(0编辑  收藏  举报