Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post

    <link> tag copying classes but not tags

    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.
    Last edited by Tails; 01-16-2004 at 08:52 AM.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #4
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rel = relationship to the file from which it is being linked.

    I take no responsibility for the above nonsense.


    Left Justified

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.)
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •