-1

I'm trying to have a background image in the header of my website but as of now it won't show. My file setup is as follows:

D:\ mywebsite

Image, home.css, index.html

Image rocks.jpg

The code I currently have is :

<div class="header-image" style=background-image: url("../Image/rocks.jpg")>
</div>

Edit

CSS:

#header .header-image {
    width: 100%;
    height: 400px;
    background-position: left center;
    background-size: 100%;
    background-repeat: no-repeat;
}
im brett
  • 33
  • 2
  • 12

2 Answers2

2

Your style attribute should have quotation marks around the in-line css, and the .. in the file path will be sending you back a directory (and so must be removed), like so:

style =  'background-image:url("Image/rocks.jpg");'

EDIT: Note that you must use single quotes to surround the css or the double quotes within url("Image/rocks.jpg") will be interpreted as closing the quotes.

0

if your directory is setup like

  • D:\mywebsite\

  • D:\mywebsite\index.html

  • D:\mywebsite\Image\

Then this will be your answer

<div class="header-image" style=background-image: url("Image/rocks.jpg")>
</div>
Josh S.
  • 612
  • 3
  • 8