【问题标题】:How to resolve CSS background image not loading on a Django template如何解决没有在 Django 模板上加载的 CSS 背景图像
【发布时间】:2020-11-12 08:06:12
【问题描述】:

嘿,所以我正在尝试将背景图像注入到我的 Django 模板中,但是由于某种原因,我不知道为什么它没有加载我尝试在 html(**) 标记上进行内联样式设置,但没有

我试图制作一个外部 css 文件,但仍然无法正常工作,请你告诉我我在这里可能做错了什么。

** 下面是我要将背景图片放入的html标签的代码**

    <div class="hero-wrap js-fullheight" data-stellar-background-ratio="0.5">
  <div class="overlay"></div>
  <div class="container">
    <div class="row no-gutters slider-text js-fullheight align-items-center justify-content-start" data-scrollax-parent="true">
      <div class="col-md-6 ftco-animate">
        <h2 class="subheading">Leave the house cleaning chores to us</h2>
        <h1 class="mb-4">Let us do the dirty work, so you don't have to.</h1>
        <p><a href="#" class="btn btn-primary mr-md-4 py-2 px-4">Learn more <span class="ion-ios-arrow-forward"></span></a></p>
      </div>
    </div>
  </div>
</div>

下面是我为测试它是否可以使用外部样式表而制作的外部 css 文件

.hero-wrap js-fullheight{

background-image: url('static/images/bg_1.jpg');
}

如果可能的话,你能教我如何使用 Django 模板在 html 标签上制作内联背景图像

【问题讨论】:

标签: html css django django-templates


【解决方案1】:

试试这个:

<div class="hero-wrap js-fullheight" data-stellar-background-ratio="0.5" style="background-image: url({% static '/images/bg_1.jpg' %});">

【讨论】:

    猜你喜欢
    • 2019-04-26
    • 2018-04-20
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 2013-07-08
    • 2014-02-17
    • 1970-01-01
    相关资源
    最近更新 更多