2013-04-02 50 views
0

[已更新]使用divs +表格中的內容進行背景拉伸

我想放置覆蓋整個窗口和div和表格中內容的拉伸背景圖像。

此代碼工作正常:

<!doctype html> 
<html> 
<head> 
<title>Background to fit screen</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta http-equiv="Imagetoolbar" content="no"> 

<style type="text/css"> 
/* pushes the page to the full capacity of the viewing area */ 
html {height:100%;} 
body {height:100%; margin:0; padding:0;} 
/* prepares the background image to full capacity of the viewing area */ 
#bg {position:fixed; top:0; left:0; width:100%; height:100%;} 
/* places the content ontop of the background image */ 
#content {position:relative; z-index:1;} 
</style> 
</head> 

<body> 
<div id="bg"><img src="../images/background.jpg" width="100%" height="100%" alt=""></div> 
<div id="content"> 

<table> 
<tr> 
<td> 
<img src="images/1.jpg"> 
</td> 
<td> 
<img src="images/2.jpg"> 
</td> 
</tr> 
</table> 

</div> 
</body> 
</html> 

的問題是在表的單元格圖像之間的間距! 一旦你擁有一張有大量圖像的非常大的桌子,這很糟糕。

請幫忙!

+0

到底是IE6? –

回答

2

對於你的表格div,你可以重寫它並添加背景大小:100%100%;

<div id ="bg" style="background-image: url(../image/background.jpg); background-size: 100% 100%;"> 
    <table> 
    <!--table stuff--> 
    </table> 
</div> 

很明顯,你想把我的內聯css放入你的css文件,但是這會給你一個總體思路。隨着你的IE 6版本,因爲它不支持CSS3,你可能只想使用背景顏色。

+0

你好,謝謝! 事情是使用背景大小的圖像不成比例地延伸。 現在的問題是表格中圖像之間的間距。 – originalp

0

給你的表格寬度100%,並給予樣式表

#content { background-image:url('image.jpg'); }