base href
I saw a question about some html come acrossed one of the maililng lists I'm on this morning, and thought I'd share some about it! Since it was a relatively new piece of knowledge to me, I thought maybe it would be helpful to someone.
The <base> tag: The base element defines a default reference to external resources.
There are definite advantages to being able to specify a default location. It means that you don't need to use absolute URLs to images when using PHP or SSI headers which will be used acrossed multiple directories and subdirectories. Same goes for templates on journal/weblogs, even when you are using the design throughout the system even in archive directories. I just stick this tag inside my head before my stylesheet link:
<base href="http://your-site.com/images">
Then the src to a image only looks like this:
<img src="smile.gif">
So basically, it just makes sure that your pages know where they are in the directory structure instead of using a lot of relative paths that look like ../../image and trying to keep track of where in the structure you are! Isn't it nice to know something that could make your html files smaller or save a few keystrokes? ![]()
May 13th, 2002 at 7:16 pm
Thanks for this, Kristine! I never really understood the use of the base href.
Woot!
May 13th, 2002 at 8:06 pm
Oh, and I forgot to add…. with MT and GM, you can set this path to be equal to the URL of your blog automatically (so that if you change your location of your journal, it will auotmatically change the path) by using these:
For Movable Type:
<base href="<$MTBlogURL$>">
For Greymatter:
<base href="{{logwebpath}}">
May 13th, 2002 at 10:25 pm
WOW! Great tip!!! Did not know that one!!!! Your rock!
May 14th, 2002 at 3:53 am
I didn't know that
Although I think I will keep doing it with the absolute urls, because otherwise I'll do something like try to link to another page or something and it will go looking for images/aboutme.php, or whatever.
May 14th, 2002 at 7:56 am
Row, so just start the base href one level higher. Use
<base href="http://your-site.com/"> and then when you use images, do
<img src="images/image.gif">
and this will make it so if you point to aboutme.php, it will be under the main directory
recap - so the image is in http://yoursite.com/images/image.gif
and the file is in http://your-site.com/aboutme.php
Does that make more sense?
May 15th, 2002 at 12:37 am
Yes! Enough so that I will probably implement it.
Thanks.
February 3rd, 2005 at 12:26 am
Can you use a base href in email?