1. 程式人生 > >HTML中使背景圖片自適應瀏覽器大小

HTML中使背景圖片自適應瀏覽器大小

pub 拉伸 htm char html back 圖片 title tran

1、圖片不夠大,又background屬性不能拉伸圖片; 2、只能用個div,把其z-index值設為負,並使這個div大小為整個body大小,在div裏用<img> 3、body的background屬性去掉,要不然會被遮住

例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>hello world</title>
</head>
<body>

<div style="position:absolute; width:100%; height:100%; z-index:-1; left:0; top:0;">
<img src="th.jpg" height="100%" width="100%" style="left:0; top:0;">
</div>
</body>
</html>

HTML中使背景圖片自適應瀏覽器大小