我如何使用静态在django上在css中放置背景图片? [英] How do I put a background image on the body in css with django using static?

查看:1949
本文介绍了我如何使用静态在django上在css中放置背景图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在css中使用static在dssango上放置背景图像?

是这样的吗?我找不到任何关于此的信息。

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


解决方案

使用相对路径。

  background:url('../ assets / images / 2.gif'相对于css文件所在的文件夹。 ); 

然后在模板文件中使用它:

  {%load staticfiles%} 
< link href ={%static'css_file_address'%} =stylesheetmedia =screen>


How do I put a background image on the body in css with django using static?

Is it something like this? I can't find any information on this. Thanks.

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

解决方案

Use a relative path. Relative to the folder where the css file reside.

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

And use it in template file like this:

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

这篇关于我如何使用静态在django上在css中放置背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆