简体   繁体   中英

HTML: Local Background Image

I am trying to display an image as my background that has been saved locally within my Eclipse project.

My folder layout is as follows:

assets
    www
      myimage.jpg
      index.html

Currently, in my index.html file I have the following:

<body background-image:url("www/myimage.jpg")>

However, the background image is not appearing...

Anyone know what the problem might be?

Thanks for your help.

  • Problem 1: You have placed a CSS rule in your HTML as if it was an HTML attribute (which it isn't).
  • Problem 2: You have given a path that isn't relative to your stylesheet. Since you don't have a CSS file in your directory listing, let's assume you are using an inline stylesheet. The files are therefore in the same directory.

Move it to a ruleset in your stylesheet, and fix the path.

<style>
body {
    background-image: url("myimage.jpg");
}
</style>

do it like quentin said.

furthermore you can do this:

<body style="background-image:url('www/myimage.jpg')">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM