fize4ever Posted November 3, 2010 Report Share Posted November 3, 2010 Hey all, just me passing by with another topic In CSS, is it preferred to write the full image path all the way from the "http" to the image format (such as png, gif, etc), or should we shortcut it to the directory that contain the images like this: "/images/filename.format" So what's preferred and what isn't? Thanks in advance to everyone who took the time to read this topic Also, thank you Killersites for always helping me out, I must be such a burden Quote Link to comment Share on other sites More sharing options...
Wickham Posted November 3, 2010 Report Share Posted November 3, 2010 You should use the relative path /images/filename.jpg as it's quicker for the server to process. Use the absolute path http://www.domain-name.com/images/filename.jpg for images if you are coding an html email (html emails need a completely different coding method, using old table coding and other things). Quote Link to comment Share on other sites More sharing options...
fize4ever Posted November 3, 2010 Author Report Share Posted November 3, 2010 Things I learned from this topic: 1- I learned the names of the files paths: 1) Absolute. 2) Relative. 2- I learned that relative path is better than absolute ones. 3- The users at Killersites never fail me. As always. Thank you very much, Wickham. Quote Link to comment Share on other sites More sharing options...
LSW Posted November 3, 2010 Report Share Posted November 3, 2010 I prefer full paths. The savings for the server are minimal and the path is always right! Clearly you want one central place to work out of, that is the idea of CSS. But what if you have sub sections? Or you retire the design but want it archived? Specific for your question, yea relative would be ok, just consider this in other cases: You have a css that points your index page to the images it needs in an image folder, so images/image.jpg. Top level to folder. Now lets say you use PHP includes and break up your file into specified folders for file clarity. Now a file is in a folder called HTML. The path to the same image would be ../images/image.jpg. You should have your includes using their own folder, again it would be ../images/image.jpg If your css path is images/image.jpg then the file and include will have a broken link, if ../images/image.jpg then the index page will have a broken link. You could define it by a class, each class path uses a different path... or you use a fully qualified path complete with HTTP: etc.. Then it does not matter where the files are in the structure, the path will always lead direct to the image. I had that issue with includes and since then I always use full paths, it is safer and lest apt to break. Quote Link to comment Share on other sites More sharing options...
fize4ever Posted November 3, 2010 Author Report Share Posted November 3, 2010 I prefer full paths. The savings for the server are minimal and the path is always right! Clearly you want one central place to work out of, that is the idea of CSS. But what if you have sub sections? Or you retire the design but want it archived? Specific for your question, yea relative would be ok, just consider this in other cases: You have a css that points your index page to the images it needs in an image folder, so images/image.jpg. Top level to folder. Now lets say you use PHP includes and break up your file into specified folders for file clarity. Now a file is in a folder called HTML. The path to the same image would be ../images/image.jpg. You should have your includes using their own folder, again it would be ../images/image.jpg If your css path is images/image.jpg then the file and include will have a broken link, if ../images/image.jpg then the index page will have a broken link. You could define it by a class, each class path uses a different path... or you use a fully qualified path complete with HTTP: etc.. Then it does not matter where the files are in the structure, the path will always lead direct to the image. I had that issue with includes and since then I always use full paths, it is safer and lest apt to break. Wow, that's a very detailed and coherent post Kyle. Thank you very much for this great input Quote Link to comment Share on other sites More sharing options...
Wickham Posted November 3, 2010 Report Share Posted November 3, 2010 (edited) Who am I to argue with Kyle! However, I think most people do use relative paths and there is a relative path method that solves Kyle's situation where you move code around to different folders at different levels - use a root-relative link. These ALWAYS go back to the root directory of the website from any file at any level and work down from there to the correct directory/folder and file. http://www.motive.co.nz/glossary/linking.php#root Root-relative links always start with a / like <a href ="/index.php">Motive homepage</a> or <a href ="/images/index.php">Motive homepage</a> Edit: the root-relative links work perfectly from your host's server online, but don't work on your local computer because the root folder is C: which won't create the correct path to the file so you have to check that links work from your online page. So relative and root-relative links do have some disadvantages, which is probably why Kyle plays safe, but most of the rest of us tend to use relative and root-relative links. Edited November 3, 2010 by Wickham Quote Link to comment Share on other sites More sharing options...
LSW Posted November 3, 2010 Report Share Posted November 3, 2010 Ha! When did Brits ever not question Ami's eh? I was taught relative, and agree most do use it... but I tend to be a Maveric (*snicker* - just taking a shot at Palin and her claims to Maveric-ity in politics... ) Yea, full is just my preference. Quote Link to comment Share on other sites More sharing options...
newseed Posted November 4, 2010 Report Share Posted November 4, 2010 When it comes to menus, I use full paths when working on sites that has multiple folders. For instance, I have a site that has ecommerce(asp) in one folder, blog(php) in another, gallery(php) in another, etc. Each will use the header/footer (1 asp and 2 php) wrap to give the site the same look throughout. Even though you still have 3 or more headers to work with when it comes to editing it you can easily set up include files within those headers such as a menu. When doing this you will then need to only edit one file to update all your headers' menu regardless if it's php, asp or both. (yes you can run php on a windows server). The menu file will have to be saved as a .txt or .htm (or html) file so that each of the header's includes can render it without problems. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.