【问题标题】:How do I put a background image on the body in css with django using static?如何使用静态的 django 在 css 中将背景图像放在身体上?
【发布时间】:2015-01-22 14:11:03
【问题描述】:

如何在 django 中使用 static 在 css 中将背景图片放在 body 上?

是这样的吗?我找不到这方面的任何信息。谢谢。

{% load static %}
body {
    padding: 0 20px;
    background-image: url("{% static "assets/images/2.gif" %}");
}

【问题讨论】:

    标签: python html django static collectstatic


    【解决方案1】:

    使用相对路径。相对于 css 文件所在的文件夹。

    background: url('../assets/images/2.gif');
    

    并像这样在模板文件中使用它:

    {% load staticfiles %}
    <link href="{% static 'css_file_address' %}" rel="stylesheet" media="screen">
    

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2011-07-01
      • 2011-01-13
      • 2014-01-10
      • 2013-05-08
      • 2013-07-31
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      相关资源
      最近更新 更多