首页 > 解决方案 > 如何解决没有在 Django 模板上加载的 CSS 背景图像

问题描述

嘿,所以我试图将背景图像注入到我的 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 标签上制作内联背景图像

标签: htmlcssdjangodjango-templates

解决方案


试试这个:

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

推荐阅读