Chris McConney
Chris McConney

Reputation: 49

My CSS background won't show

I have checked and double checked the syntax, but I'm unsure why my CSS background won't load:

 body { 
  font-family: cursive,serif; 
  background: url("../images/background.jpeg") no-repeat center center;
  background-attachment: fixed;
  background-size: cover;
}

Folder Structure

--index.html
--style.css
--images
  |____ background.jpeg

Upvotes: 1

Views: 74

Answers (1)

Racil Hilan
Racil Hilan

Reputation: 25351

There are two issues in your CSS:

  • .body is used to select elements with body class (e.g. <div class="body"></div>). If you actually want to add the CSS to the <body>, remove the dot at the beginning.
  • The image is in the image subfolder of your HTML file, and the CSS file is in the root folder. You can use url("images/background.jpeg").

Here is the CSS with the above suggestions:

body {
  font-family: cursive, serif;
  background: url("images/background.jpeg") no-repeat center center;
  background-attachment: fixed;
  background-size: cover;
}

Upvotes: 3

Related Questions