【发布时间】:2018-02-15 06:33:21
【问题描述】:
我无法在我的网站上显示我的背景图片。我将背景图像放在我的 style.css 中,并将其链接到“”中。
我将 {% load staticfiles %} 放在样式上方,但我很确定这是错误的。
我检查了我的设置并且 STATIC_URL 设置是 STATIC_URL = '/static/'
这是我的CSS
style.css
body {
background:slategray url("/personal/static/personal/images/background.gif")no-repeat right bottom;
}
这是我的html代码
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Mr. Hart</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<div class="row">
<div class="col-md-8">
<a href='/' style="display: inline-block; text-decoration-color: #1a8002;">Home</a>
<a href='/blog/' style="display: inline-block; text-decoration-color: green;"> Blog </a>
<a href='/Aboutme/' style="display: inline-block; text-decoration-color: green;"> About Me </a>
<a href='/stocks/' style="display: inline-block; text-decoration-color: green;"> My stock Tips </a>
<a href='/crypto/' style="display: inline-block; text-decoration-color: green;"> Crypto </a>
</div>
<div class="col-md-4">"This is where my contacts stack,github, stocktwits, twitter, all picture links "</div>
</div>
{% load staticfiles %}
<style type="text/css">
html,
body {
background: url("{% static "/personal/style.css" %}") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
</head>
【问题讨论】:
-
您好,您尝试使用源 CSS 渲染图像,您需要图像而不是 CSS 文件。这里是您的问题背景: url("{% static "/personal/style.css" %}") 尝试使用 ASP 或 JSP 加载您的图像不知道尝试背景: url(domain/to/your/image.jpg) 问候
-
我不知道如何使用 ASP 或 JSP。我尝试通过背景将 url 直接指向图像: url("/personal/static/personal/images/background.jpg") no-repeat center center fixed;无济于事仍然空白。
-
可以肯定的是,尝试在浏览器上加载图像并将带有“http://”的 url 复制粘贴到背景:url(http/domain/to/your/image.jpg)