简体   繁体   中英

background image not displaying css/html

This is probably a really simple problem that I'm guessing has a very obvious but stupid solution but I am not seeing it. I am trying to get an image to become a tiled background and for some reason the image is not appearing nor am I getting errors. I have checked permissions and set all files and folders to 777. Can someone point out the problem for me thanks.

My CSS file:

body {
    background-image: url("images/main_background.png");
}

My HTML file:

<!DOCTYPE html>
<html>

    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/layout.css">
    </head>

<body>

    <div id="main_container">

    </div>

</body>

</html>

Your image is in images folder and css is in css folder.

images/main_background.png means that images folder is inside the css folder, but it is not.

write this:

body {
    background-image: url("../images/main_background.png"); 
}

OR

body {
    background-image: url("/images/main_background.png"); 
}

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