0

I'm trying to load an image to my page and set it as my background, below is the css and html that I am working with. The CSS page seems to load, as my test font and background colors show up but for whatever reason my background image doesn't.

I am using Django as my web framework.

Appreciate the help!

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;

}
1
  • 1
    Remove the no-repeat from background-image as you already have it in a separate property background-repeat, and see if it works. Commented Feb 8, 2017 at 9:52

3 Answers 3

1

You used background-image, so the no-repeat is not actually working. Try adding the no-repeat below as background-repeat: no-repeat;.

 background-image: url('image-url-here.png');
 background-repeat: no-repeat;
Sign up to request clarification or add additional context in comments.

4 Comments

That, or background: url('image-url-here.png') no-repeat;. But he has to choose either combined properties with background shorthand or split properties with full names. Cannot mix.
As you like, both ways make sense as long as one remains consistent within their project.
@Phum, can you post your folder structure?
@Phum, depending on where your background image is located, you may need to change the url path reference to match it. Your current image path suggesta that the personal directory is on the same level as your HTML file.
0

I've had problems like this with django, primarily because my {% static %} location was confusing me. I think this is a non-css issue, and a path issue.

It helped me to use the dev console to check for Resource Failed To Load error. It will spit out the path that the machine is looking for, and it's likely different than what you specified.

I.e. is your css file located along

personal/static/personal/img/home.jpg

relative to your css file? You might just need to back up a directory, i.e.

../personal/static/personal/img/home.jpg

Either way, the console should give you your path, and use that to determine where your CSS file is digging for the image.

Comments

0

If your CSS files are in a path such as /static/css/style.css and the images are under a path such as /static/images/test.jpg then you have to place the test.jpg image directly in the folder with the style.css i.e. /static/css/test.jpg and in your HTML file give it the name test.jpg without using the static path i.e. background-image:url('test.jpg');:)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.