homepage Welcome to WebmasterWorld Guest from 54.227.89.236
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
css base url
Is there a way to tell a CSS file to always use a base URL just like href?
scrfix




msg:3663649
 2:44 pm on May 31, 2008 (gmt 0)

Updated
As I am looking at this more and more. If I utilize the http protocol for my includes within my php files rather than ../ this should solve my issue. This is more of a php question than a CSS question. Please move this to the appropriate forum with a different header. That would be PHP relative includes vs. PHP absolute includes.

Original
I have a minor issue.

I am using relative locations (ie. ../)for my images found within my CSS file.

This has been working great as long as I keep everything I do in the root directory. I started utilizing different directories to keep my code in and found out that the further I go away from the root directory the more issues I am starting to have utilizing the above method. (This goes the same for my JS file directory)

Problem
Reference the chart below The problem that is happening is when the public directory attempts to access the css file it looks for the css file as support/css/css.css rather than root/css/css.css

I utilize multiple include files and have massive amounts of code to make everything on the website work together so I cannot re-write everything and start over again.

Objective
Without rewriting everything and moving everything into different directories, I would like to be able to utilize the same php include files and the same CSS, JS, Image files, etc so that when I make a change to the website I only have to do so in 1 file to make it site wide.

Example:
Root Directory has the following directories:
(You will notice that in the Root there is are CSS, JS, Images and Support Directories. You will also notice there is a Public Directory located within the Support directory. This is where the issues is at.)

Root

CSS --> All Images Referenced as ../Images/
JS
Images
Support --> Public --> References A CSS.PHP file as ../../css.php

A portion of the contents of the CSS.PHP are:
<link rel="stylesheet" type="text/css" href="../css/css.css" />

I thought about utilizing absolute references but by personal preference would like to stick to relative references.
What do you think?
Any ideas?

 

rocknbil




msg:3663666
 3:41 pm on May 31, 2008 (gmt 0)

Welcome aboard scrfix! As for the original question, I am not sure - however there is a really good way to "start at root" across all your markup - CSS, Javascript, and HTML. Instead of

../some_directory

Always use

/some_directory

The / means start at the domain root. So you can move a file containing this

/support/public/references/file.html

**anywhere** on your site and it will always locate file.html.

The same is true in your scripts,

$css = '/css/scripts/scripts.css';

and your css

background: url(/images/some_dir/image.gif);

The down side: requires a web server; working on these files locally on either PC or Mac will not find the locations. You can temporarily revert to relative using a S & R function in your editor.

scrfix




msg:3663998
 3:31 am on Jun 1, 2008 (gmt 0)

That's awesome. I was knocking my head around attempting to figure that out. I thought it was ./ but that didn't work. I tried everything but that. I even tried ../../../../ just to ensure that I was in the root. lol (That didn't work either).

(I have actually been a member of webmasterworld for quite some time but my original username and password were not working and the password recovery page was non existent. I had to create a new username.)

Thanks,

Wayne

phranque




msg:3664128
 9:15 am on Jun 1, 2008 (gmt 0)

scrfix:
fyi,
. (or ./) means the current directory
.. (or ../) means the parent of the current directory
/ means the root directory

so ../../../../ means go "up" 4 directory levels.

rocknbil




msg:3664245
 3:18 pm on Jun 1, 2008 (gmt 0)

I even tried ../../../../

Been there, driven insane, barely recovered. :-)

scrfix




msg:3664263
 3:40 pm on Jun 1, 2008 (gmt 0)

Thanks Everyone. *SCRFix Dances a Jig, So Happy*

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved