phparmy
asked on
using absolute paths in css files.
i have disorganized directories in my web project.
directory is like
www/myproject
........................./ con.php
........................./ index.php
........................./ conf.php
........................./ images/mai npage/1.jp g
........................./ images/2.j pg
........................./ css/style. css
........................./ lib/functi ons.php
........................./ lib/templa te/mainpag e.php
........................./ user/index .php
......................../a dmin/exter nal/tech.p hp
-------------------------- ---------- ---------- ---------- --------
in my style.css
#box{
background-image:url(../im ages/mainp age/1.jpg) ;
}
#line{
background-image:url(../im ages/2.jpg );
}
when i include this css file from /user/index.php it works fine but when i call this css from /admin/external/tech.php
is there any solution to make absolute paths for css files.
i want to make this
#box{
background-image:url(/mypr oject/imag es/mainpag e/1.jpg);
}
#line{
background-image:url(/mypr oject/imag es/2.jpg);
}
i know how to do this in php files or in html via javascript. but i can not find any way to do this in css.
thanks.
directory is like
www/myproject
........................./
........................./
........................./
........................./
........................./
........................./
........................./
........................./
........................./
......................../a
--------------------------
in my style.css
#box{
background-image:url(../im
}
#line{
background-image:url(../im
}
when i include this css file from /user/index.php it works fine but when i call this css from /admin/external/tech.php
is there any solution to make absolute paths for css files.
i want to make this
#box{
background-image:url(/mypr
}
#line{
background-image:url(/mypr
}
i know how to do this in php files or in html via javascript. but i can not find any way to do this in css.
thanks.
>>i want to make this
#box{
background-image:url(/mypr oject/imag es/mainpag e/1.jpg);
}
#line{
background-image:url(/mypr oject/imag es/2.jpg);
}
Get rid of "/myproject":
i want to make this
#box{
background-image:url(/imag es/mainpag e/1.jpg);
}
#line{
background-image:url(/imag es/2.jpg);
}
#box{
background-image:url(/mypr
}
#line{
background-image:url(/mypr
}
Get rid of "/myproject":
i want to make this
#box{
background-image:url(/imag
}
#line{
background-image:url(/imag
}
As the syntax "url()" suggests, the part in bracket is a URL.
You may use relative URLSs ans in your example, i.e. url(foo1.jpg) or url(dir/foo2.jpg) or url(../foo3.jpg)
but also url(/absdir/foo4.jpg) and of course url(ftp://hostname/path/foo5.jpg)
Assuming your CSS file is retrieved as http://yourserver/something/cssdir/cssfile.css, the effect of the above examples is that the client will look for
http://yourserver/something/cssdir/foo1.jpg
http://yourserver/something/cssdir/dir/foo1.jpg
http://yourserver/something/foo3.jpg
http://yourserver/absdir/foo4.jpg
ftp://hostname/path/foo5.jpg
Relative path is always relative to the place where the containing file is, absolute path is from the webroot of the same webserver and with scheme and host you may even reference external resources.
You may use relative URLSs ans in your example, i.e. url(foo1.jpg) or url(dir/foo2.jpg) or url(../foo3.jpg)
but also url(/absdir/foo4.jpg) and of course url(ftp://hostname/path/foo5.jpg)
Assuming your CSS file is retrieved as http://yourserver/something/cssdir/cssfile.css, the effect of the above examples is that the client will look for
http://yourserver/something/cssdir/foo1.jpg
http://yourserver/something/cssdir/dir/foo1.jpg
http://yourserver/something/foo3.jpg
http://yourserver/absdir/foo4.jpg
ftp://hostname/path/foo5.jpg
Relative path is always relative to the place where the containing file is, absolute path is from the webroot of the same webserver and with scheme and host you may even reference external resources.
ASKER
i am asking how can i define this via javascript or etc. because i do not want to make changes in my css when i setup my web application to new server.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to not make changes in your site when you upload it, you don't want to use absolute paths at all!!! You want to use relative paths!
Hi phparmy,
I was wondering why css in your code is not working properly, even you already have correct directory structure of your project folders, can you please provide the link where your project is live,
so that i can help you out :D
Vinay Rajput
I was wondering why css in your code is not working properly, even you already have correct directory structure of your project folders, can you please provide the link where your project is live,
so that i can help you out :D
Vinay Rajput
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
main problem is.
www.phparmy.com/project1/
www.phparmy.com/project2/
you see it is not main root in one css you have to write
/project1/images/image1.jp g
/project2/images/image2.jp g
but i think there is no way to do this automatic. thanks.
www.phparmy.com/project1/
www.phparmy.com/project2/
you see it is not main root in one css you have to write
/project1/images/image1.jp
/project2/images/image2.jp
but i think there is no way to do this automatic. thanks.
if your site is secure using ssl your path would look like this = https://www.etc, etc, etc
hope that helps
FDM