css background-image对表对象不起作用

时间:2016-01-27 11:19:38

标签: html css django

在我的Django应用程序中,我想将背景图像放在表格中。问题是图像没有显示。这是代码:

<table style="background-image: url('/static/assets/img/myimage.png') ;background-position: 0 100% !important;background-repeat: repeat-x ;background-size: 40px 3px">
Hello!
</table> 

如果我在div对象中放入相同的css样式都可以正常工作。例如:

<div style="background-image: url('/static/assets/img/myimage.png') ;background-position: 0 100% !important;background-repeat: repeat-x ;background-size: 40px 3px">
Hello!
</div> 

我的错误在哪里?非常感谢您的帮助

EDIT1

我想在django模板中插入电子邮件html文件。我使用'include'并且所有作品都用于图像,但不适用于背景图像样式。图像位置是正确的(如果我使用'div'而不是'table'都可以)。我有引导程序

EDIT2

这是完整的代码。在表格中我没有看到背景图片

<!-- ======= section ======= -->
<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="34302d" style="background-image: url('http://themastermail.com/envato/omail/demo/layout2/img/testi-bg.jpg') !important; background-size: cover; background-position: top center; background-repeat: no-repeat;" background="http://themastermail.com/envato/omail/demo/layout2/img/testi-bg.jpg">

    <tr><td height="60" style="font-size: 60px; line-height: 60px;">&nbsp;</td></tr>

    <tr>
        <td align="center">

            <table border="0" width="590" align="center" cellpadding="0" cellspacing="0" class="container590">

                <tr>
                    <td>
                        <table border="0" width="580" align="center" cellpadding="0" cellspacing="0" class="container580">

                            <tr>

                                <td align="center" style="color: #b9bcc7; font-size: 16px; font-family: 'Open Sans', Calibri, sans-serif; line-height: 30px;" class="title_color">
                                    <!-- ======= section text ====== -->

                                    <div style="line-height: 30px">

                                            <em>Proin eget massa tincidunt, lobortis ex nec, placerat odio. Mauris gravida nulla id laoreet ornare. Maecenas sagittis elit metus, eget pellentesque couleur non categorize rouge vert bleu.</em>

                                    </div>
                                </td>

                            </tr>

                        </table>
                    </td>
                </tr>

                <tr><td height="35" style="font-size: 35px; line-height: 35px;">&nbsp;</td></tr>

                <tr>
                    <td align="center">
                        <table border="0" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                                <td align="left" width="80">
                                    <a href="" style=" border-style: none !important; border: 0 !important;"><img src="http://themastermail.com/envato/omail/demo/layout2/img/testi-img.png" style="display: block; width: auto;" width="70" border="0" alt=""/></a>
                                </td>

                                <td align="left" style="color: #ffffff; font-size: 14px; font-family: Raleway, Calibri, sans-serif; mso-line-height-rule: exactly; line-height: 24px;" class="title_color">

                                    <!-- ======= section header ======= -->

                                    <div style="line-height: 24px;">

                                            Marta Clarcks<br><a href="" style="color: #f29a27; text-decoration: none;">envato.com</a>

                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

            </table>
        </td>
    </tr>

    <tr><td height="60" style="font-size: 60px; line-height: 60px;">&nbsp;</td></tr>

</table>
<!-- ======= end section ====== -->

2 个答案:

答案 0 :(得分:0)

您在!标记上遗漏了!important

<table style="background-image: url('/static/assets/img/myimage.png') !important;background-position: 0 100% !important;background-repeat: repeat-x !;background-size: 40px 3px">
Hello!
</table>

但由于你的字段中没有trtd等,它可能仍然无法显示,你应该尝试:

<table style="background-image: url('/static/assets/img/myimage.png') !important;background-position: 0 100% !important;background-repeat: repeat-x !;background-size: 40px 3px; display: block;">
  <tr>
    <td>
      <p>hello</p>
    </td>
  </tr>
</table> 

答案 1 :(得分:0)

试试这个

    <table style="background-image: url('static/assets/img/myimage.png') !important;background-position: 0 100% !important;background-repeat: repeat-x !;background-size: 40px 3px">
    <tr><td>Hello!</td></tr>
    </table> 

文件夹结构
css.css
静态/