2013-04-15 24 views
0

在我的網站中,在特定的表格中,我必須插入圖像作爲背景。我這樣做了,但圖像看起來像雙重圖像,因爲圖像比單元格的寬度和高度要小。如何在django中爲模板應用背景圖像

在背景圖像單元格中,我使用無重複來結束重複顯示同一圖像,但它不起作用。我在django框架中使用html設計網頁。

模板

<td background="{{ STATIC_URL }}images/sample.JPG" no-repeat;> 

我可能知道如何取消同一背景圖像的重複顯示錶格單元格。

感謝

回答

0

嘗試像下面......它會幫助你...

no repeats the image background它也Stretch the image to Table Cell ..

CSS:

<style> 
.tdStyle 
{ 
background-image:url('{{ STATIC_URL }}images/sample.JPG'); 
background-repeat:no-repeat; 
background-size:100%; 
} 
</style> 

,從而支持瀏覽器,你可以將下面幾行添加到CSS:

-moz-background-size: 100%; /* Gecko 1.9.2 (Firefox 3.6) */ 
-o-background-size: 100%; /* Opera 9.5 */ 
-webkit-background-size: 100%; /* Safari 3.0 */ 
-khtml-background-size: 100%; /* Konqueror 3.5.4 */ 
-moz-border-image: url(mtn.jpg) 0; /* Gecko 1.9.1 (Firefox 3.5) */ 

HTML:

<td class="tdStyle"> 
+2

note:background-size是一個CSS3屬性,它不適用於舊版瀏覽器,而不包括某些javascript備份。 –

3

'no-repeat'不是有效的HTML屬性。你爲什麼不使用style屬性或一個合適的CSS包含文件?

<td style="background: url('{{ STATIC_URL }}images/sample.JPG') no-repeat;"> 
+0

創建一個[fiddle](http://jsfiddle.net/),讓人們更好地理解您遇到的問題 –

0

順便說一句,我們創建了一個reusable app允許通過管理網站更改背景圖片。

3

看看我是如何做的: 在我把下面的行模板:

<body id="bg" style="background-image: url('{% static "images/33.jpg"%}')";> 

並在CSS:

#bg{ 
    background-size: 1800px 900px; 
    background-repeat: no-repeat; 
    background-position: top; 
    background-attachment: fixed; 
} 

因此,我得到一個固定的背景,並與屏幕的比例。

相關問題