如何在 django 中为模板应用背景图像 [英] How to apply background image for an templates in django
问题描述
在我的网站中,在一个特定的表格中,我必须插入一个图像作为背景.我这样做了,但图像看起来像双重图像,因为图像小于单元格宽度和高度,它正在重叠.
In my site, in a table of particular I have to insert a image as background. I did that but the image looks like double image as the image is smaller than cell width and height it is getting overlap.
在背景图像单元格中,我使用 no-repeat 来结束同一图像的重复显示,但它不起作用.我正在使用 django 框架中的 html 设计网页.
In background image cell I used no-repeat to end the repeat display of same image, but it is not working. I am designing web page using html in django framework.
模板是
<td background="{{ STATIC_URL }}images/sample.JPG" no-repeat;>
我可以知道如何取消表格单元格中相同背景图像的重复显示.
May I know how to cancel the repeat display of same background image in a table cell.
谢谢
推荐答案
试试下面的方法...它会帮助你...
Try like below... It will help you...
它不重复图像背景
,它也将图像拉伸到表格单元
..
CSS:
<style>
.tdStyle
{
background-image:url('{{ STATIC_URL }}images/sample.JPG');
background-repeat:no-repeat;
background-size:100%;
}
</style>
要支持旧浏览器,您可以将以下几行添加到 CSS 中:
To Support Old Browsers you can add the below lines to 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">
这篇关于如何在 django 中为模板应用背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!