How to get the root directory of wordpress in css

How can I get the root directory in css of wordpress?

My css is this:

Read More
#bg{
display: block;
background: url('/assets/images/_userfiles/bg_1.png') no-repeat center center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

I tought this would link to the root of wordpress folder, but it doesn’t so how can I possibly get this right?

My assets map is in the very root of the wordpress folder.

Related posts

Leave a Reply

1 comment

  1. The CSS you used gives you the domain root.

    So if your domain is http://www.site.com your css tries to request:

    http://www.site.com/assets/images/_userfiles/bg_1.png

    files mentioned in CSS when not used with an absolute path as you have done are relative to your css stylesheet file.

    so, of you have your css file in:

    http://www.site.com/wp-content/themes/mytheme/style.css

    And you have your files in:

    http://www.site.com/wp-content/themes/mytheme/assets/images/_userfiles/bg_1.png

    you only need to remove your first ‘/’ from your your css url();

    #bg
       {
       display: block;
       background: url('assets/images/_userfiles/bg_1.png') no-repeat center center;
       position: fixed;
       top: 0;
       left: 0;
       width: 100%;
       height: 100%;
       }
    

    Recap

    The base url is relative to your css file.

    To go up one directory relative to your css file use url(../path/to/file/that/is/one/directory/up/from/your/css/file);

    So, just examine in your ftp explorer which directory structure your css file is located and figure out your way to your assets folder.

    You can use as many ../../../ you wish. If the max is reached the browser will default to the url of the site as if you had used a ‘/’ to start your url.