...

View Full Version : <link> tag copying classes but not tags



Tails
01-16-2004, 08:36 AM
On a page (index.htm), I had this for styles:

<style type="text/css">
div,h2{text-align:center}
div table{width:100%}
span{font-size:large}
.l{background-color: #8060D0; width: 2%;text-align:center;color:yellow}
.c{background-color: #FFB600}
.g{background-color: #CCCCCC}
.r{background-color: #60D080;text-align:right}
.t{background-color: #D09080;width:45%}
img{border:0}
</style>

I tried linking another page in the same directory to it with the link tag.

<link rel="stylesheet" href="index.htm" />

The classes .c and .g worked fine when the page needed to use them. But when I made a <div> tag, it was not centered like it was on the main page. Why could this be? If it's related, I'm using an XHTML 1.0 Strict doctype.

EDIT: The W3C CSS validator doesn't like it, so maybe it was just another IE trick that was too good to be true.

liorean
01-16-2004, 10:05 AM
The stylesheet should be in a file of it's own, normally in a .css file, but the file name is irrelevant as long as it is sent as 'text/css'. That file should contain ONLY style rules (or other CSS constructs), no HTML comments or other non-CSS code.

The link tag itself should minimally look like this:
<link type="text/css" rel="stylesheet" href="uri-to-css-file">

Also note that text-align should affect text alignment only, and not affect box positions. That should be done using an explicit width and setting left and right margins to auto instead.

Tails
01-16-2004, 12:55 PM
The validator never expected a type attribute (I never would have thought of it). But why didn't they make it expect type instead of "rel"? What's rel supposed to be anyway? There's many mysterious things about the <link> tag. I made a common css file to share between both pages and it works fine now.

mindlessLemming
01-16-2004, 01:13 PM
rel = relationship to the file from which it is being linked.

liorean
01-16-2004, 01:22 PM
The type attribute isn't for the validator's benefit. Link elements doesn't need to have a type. However, link elements that are including a stylesheet need to have it, since it tells the browser whether the target document is of a format it is able to parse, and therefore download it. At least Mozilla doesn't bother downloading documents expected to be of unparsable types.

Tails
01-16-2004, 02:33 PM
This makes this use of the <link> tag sound alot more like an include than anything (best definition I've heard of the tag too). But what else can they include besides stylesheets? On the W3 I've seen them the hrefs point to bookmarks and have title tags as well, but that's all I've seen with this tag.

liorean
01-16-2004, 02:51 PM
The link element was initially thought of as a method of providing a page navigation - read more about it at <http://www.w3.org/TR/REC-html40/struct/links.html> and more specifically about how you can use it at <http://www.w3.org/TR/REC-html40/types.html#type-links>. It is now a very versatile tag, which may provide the entire site navigation, if your target browsers are NCSA Mosaic or Mozilla. (Or any other that support this usage of the link element.)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum