Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get background image present in other folder using css?

Guys this is my folder structure

Project

  • index.php
  • css

    style.css

  • js

    javascript.js

  • image

    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 guys tell me where am i wrong such that i can correct it so that my background image is displayed.

like image 657
Mani Kandan Avatar asked Jan 08 '23 12:01

Mani Kandan


2 Answers

I believe this is the issue.

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

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

../ - This means one directory up to give the image location, as in your case, it is inside image directory.

Hope this helps.

like image 187
Nitesh Avatar answered Mar 24 '23 12:03

Nitesh


It should look like this:

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

That is a really common mistake, even with me. You need the double dots to go back one folder, since your stylesheet is inside the css folder and your background is inside the images folder. Also, once you get that fixed, you could perfectly align it in the back using

background-size: cover;

.. and with the prefixes, it would look like this.

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

I hope this answers your question.

like image 41
Ishan Marikar Avatar answered Mar 24 '23 11:03

Ishan Marikar