B daddy909
B daddy909

Reputation: 21

html css not going well

Am I typing something in wrong for the background image not to be working? All the folders and files are in the correct spot for it to work.

<!DOCTYPE html>
<html>
    <head>
      <meta charset="utf-8">
      <title>First Project</title>
      <link rel="stylesheet" href="css.folder/first_project.css">
    </head>
    <body>
      <h1>marvelous day</h1>
    </body>
</html>

h1 {
    color: blue;
}

body {
    background-image: url("img/pattern.png");
    }

Upvotes: 0

Views: 42

Answers (2)

wazz
wazz

Reputation: 5058

You can add a slash at the beginning so it starts looking from the root:

background-image: url("/img/pattern.png");

Upvotes: 0

nitrex
nitrex

Reputation: 542

I suppose your folder structure is the following

  • css
    • first_project.css
  • img
    • pattern.png
  • index.html

if this is the case in your css you should add ../ before your url so that the browser can know where the image is located

body{
    background-image:url("../img/pattern.png");
}

pay attention for relative urls in your css

Upvotes: 1

Related Questions