我正在尝试将图像加载到页面上并将其设置为背景,以下是我正在使用的css和html。 CSS页面似乎已加载,因为显示了我的测试字体和背景颜色,但是由于任何原因我的背景图像都没有显示。

我正在使用Django作为我的Web框架。

感谢帮助!

HTML:

<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">

<head>
    <title>Test</title>
    <meta charset="utf-8" />

 <link rel="stylesheet" href="{% static 'personal/css/frontpagebackground.css' %}" type = "text/css"/>
</head>

<body>


<p>This is a test</p>


</body>
</html>


CSS:

body
{
background-image:url(personal/static/personal/img/home.jpg) no-repeat;
background-repeat:no-repeat;
background-size:100%;
background-color: green;
min-height: 100%;
}


p {
    font-style: italic;
    color: red;

}

最佳答案

您使用的是background-image,因此no-repeat实际上不起作用。尝试将以下no-repeat添加为background-repeat: no-repeat;

 background-image: url('image-url-here.png');
 background-repeat: no-repeat;

09-10 05:12
查看更多