【问题标题】:Django: Unable to set background-image to a button in templateDjango:无法将背景图像设置为模板中的按钮
【发布时间】:2021-03-19 00:43:34
【问题描述】:

我正在尝试将背景图像设置为按钮但未显示。当我将鼠标悬停在背景 url 上时,在 inpect 元素中它会显示图像。表示网址正确。

<button style="background-image: url('{{  mobile_brand.image.url }}'); !important;
           background-repeat: no-repeat;" 
           name="brand" id="brand" class="btn btn-outline-info m-1" 
           type="submit" value={{mobile_brand}}></button>

我尝试了不同的变体,例如使用输入而不是按钮。将静态放在网址中。消除昏迷,背景重复。并尝试给出完整的路径。没有任何效果。 谢谢你的帮助。

【问题讨论】:

    标签: django django-templates


    【解决方案1】:

    刚刚解决了

               <button name="brand" id="brand" class="btn btn-outline-info m-1" 
               type="submit" value={{mobile_brand}}>{{mobile_brand}}
               <img class='brand-btn-icon' src={{mobile_brand.image.url}}/>
               </button>
    

    现在感觉很愚蠢,但有时很难弄清楚简单的事情。谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多