How to get background image in another folder using css?

Guys this is my folder structure

Project

  • index.php
  • CSS

    style.css

  • Js

    javascript.js

  • picture

    background.jpeg

style.css

body{
background-image: url("image\background.jpeg");
}

index.php

<html>
<head>
    <title>Todo Application</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div id = "header">
    hiuiiiii
    </div>
</body>
</html>

So the guys are telling me where I'm wrong, so I can fix it so that the background image is displayed.

+4
source share
6 answers

I think this is a problem.

Invalid - url ("image \ background.jpeg");

Fix - url ("../image/background.jpg");

../ - This means that one directory to indicate the location of the image, as in your case, is located inside the image directory.

Hope this helps.

+4

:

body {
     background-image: url("../image/background.jpeg"); }

, . , , css, . , , ,

background-size: cover;

.. , .

  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;

, .

+2

URL- CSS , CSS. , URL- . , "sibling" , , / ../ . , URL- /, \.

body{
    background-image:url("/image/background.jpeg");
}
body{
    background-image:url("../image/background.jpeg");
}
+2

:

background:url("../images/background.jpg") no-repeat;

background-image:url("../images/background.jpg");

use ../before folder name

+1
source

Ok, I have the same problem when I try to solve your problem locally. But now, I do it works like.

CSS

body{
background: url("../image/background.jpg");
}

HTML:

<head>
    <title>Todo Application</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div id = "header">
    hiuiiiii
    </div>
</body>
</html>

Hope this helps.

+1
source

Hope this can help: url ("../image/background.jpg");

-1
source

Source: https://habr.com/ru/post/1584253/


All Articles