HTML中使背景图片自适应浏览器大小

来源:互联网 发布:期货技术分析软件 编辑:程序博客网 时间:2024/04/29 03:59
 由于<body>标签的图片不能够拉伸,

解决办法:

1、图片不够大,又background属性不能拉伸图片; 2、只能用个div,把其z-index值设为负,并使这个div大小为整个body大小,在div里用<img> 3、body的background属性去掉,要不然会被遮住

 

[html] view plain copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">    
  2. <html>    
  3. <head>    
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">    
  5. <title>hello world</title>    
  6. </head>    
  7. <body>    
  8. <div id="Layer1" style="position:absolute; width:100%; height:100%; z-index:-1">    
  9. <img src="pictures/background.jpg" height="100%" width="100%"/>    
  10. </div>    
  11. </body>    
  12. </html>    

 

有一点不完美!楼主代码应该改成

[html] view plain copy
  1. <div style="position:absolute; width:100%; height:100%; z-index:-1; left:0; top:0;">      
  2. <img src="pictures/background.jpg" height="100%" width="100%" style="left:0; top:0;">      
  3. </div>  

如此做才使得图片周围没有多余的白边。

0 0
原创粉丝点击