CSS root directory

前端 未结 6 1461
小鲜肉
小鲜肉 2020-12-13 00:01

I have a style sheet where I include background images.

background: url(../Images/myImage.png);

problem is, pages from different directorie

相关标签:
6条回答
  • 2020-12-13 00:17

    click here for good explaination!

    All you need to know about relative file paths:

    Starting with "/" returns to the root directory and starts there

    Starting with "../" moves one directory backward and starts there

    Starting with "../../" moves two directories backward and starts there (and so on...)

    To move forward, just start with the first subdirectory and keep moving forward

    0 讨论(0)
  • 2020-12-13 00:34

    I use a relative path solution,

    ./../../../../../images/img.png

    every ../ will take you one folder up towards the root. Hope this helps..

    0 讨论(0)
  • 2020-12-13 00:35

    For example your directory is like this:

    Desktop >
            ProjectFolder >
                          index.html
                          css >
                              style.css
                          images >
                                 img.png
    

    You are at your style.css and you want to use img.png as a background-image, use this:

    url("../images/img.png")
    

    Works for me!

    0 讨论(0)
  • 2020-12-13 00:36

    This problem that the "../" means step up (parent folder) link "../images/img.png" will not work because when you are using ajax like data passing to the web site from the server.

    What you have to do is point the image location to root with "./" then the second folder (in this case the second folder is "images")

    url("./images/img.png")
    

    if you have folders like this

    root -> content -> images

    then you use url("./content/images/img.png"), remember your image will not visible in the editor window but when it passed to the browser using ajax it will display.

    0 讨论(0)
  • 2020-12-13 00:38

    In the CSS all you have to do is put url(logical path to the image file)

    0 讨论(0)
  • 2020-12-13 00:44
    /Images/myImage.png
    

    this has to be in root of your domain/subdomain

    http://website.to/Images/myImage.png

    and it will work

    However, I think it would work like this, too

    • images
      • yourimage.png
    • styles
      • style.css

    style.css:

    body{
        background: url(../images/yourimage.png);
    }
    
    0 讨论(0)
提交回复
热议问题