HTML will not link to CSS file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimchapuk
    New Member
    • Aug 2007
    • 9

    HTML will not link to CSS file

    I just started to learn. I can't get the code in my CSS file to link to my HTML file to produce the web page I want.

    The code I've used is;

    <link rel="stylesheet " type="txt/css" href="bkkcss.cs s /">


    And in the CSS sheet is;

    body
    {margin:0;
    padding:0;
    background-color:##003300
    }


    And when I validate I get the following which I don't fully understand;

    The validator has found the following problem(s) prior to validation, which should be addressed in priority:

    Missing "charset" attribute for "text/xml" document.
    The HTTP Content-Type header (text/xml) sent by your web browser (Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)) did not contain a "charset" parameter, but the Content-Type was one of the XML text/* sub-types.

    The relevant specification (RFC 3023) specifies a strong default of "us-ascii" for such documents so we will use this value regardless of any encoding you may have indicated elsewhere.

    If you would like to use a different encoding, you should arrange to have your browser send this new encoding information.

    Conflict between Mime Type and Document Type
    The document is being served with the text/xml Mime Type which is not a registered media type for the XHTML 1.1 Document Type. The recommended media type for this document is: application/xhtml+xml

    Using a wrong media type for a certain document type may confuse the validator and other user agents with respect to the nature of the document, and you may get some erroneous validation errors. How to fix this problem? One of the following techniques should help:

    If you are serving a static file on a Web server, changing its extension should help. Use e.g .xhtml for XHTML or .mathml for MathML.
    You may need to reconfigure your Web server. This Setting up MIME Types tutorial has instructions for Apache, Tomcat and IIS.
    If the document is generated dynamically, the scripting language should allow you to set up the mime type: this article on MIME Types and Content Negotiation has examples in PHP, Perl, and ASP.


    I am in an internet place in Bangkok so maybe the browser isn't very good. I've tried Firefox and IE.

    When I put the CSS code and HTML code in the same file I'm getting things to work ok.

    Regards

    Jim Walsh
  • MrPutty
    New Member
    • Aug 2007
    • 13

    #2
    Hey Jim,

    have you checked your paths? Throw both files in the same directory.

    <link rel="stylesheet " type="txt/css" href="bkkcss.cs s /">
    and try without "/"
    <link rel="stylesheet " type="txt/css" href="bkkcss.cs s">

    That should work for you.

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      1) For the background-color, there should be only one '#' symbol.
      2) There is no mime-type of text/xml and should be changed to 'application/xml' but are you truly using XML?
      3) application/xhtml+xml is only recognized by modern browsers and not Internet Explorer.

      Comment

      • jimchapuk
        New Member
        • Aug 2007
        • 9

        #4
        Originally posted by MrPutty
        Hey Jim,

        have you checked your paths? Throw both files in the same directory.

        <link rel="stylesheet " type="txt/css" href="bkkcss.cs s /">
        and try without "/"
        <link rel="stylesheet " type="txt/css" href="bkkcss.cs s">

        That should work for you.
        Thanks for your time Mr Putty. Truly appreciated.

        I took the / off and it worked just fine.

        Regards

        Jim Walsh

        Comment

        • jimchapuk
          New Member
          • Aug 2007
          • 9

          #5
          Originally posted by drhowarddrfine
          1) For the background-color, there should be only one '#' symbol.
          2) There is no mime-type of text/xml and should be changed to 'application/xml' but are you truly using XML?
          3) application/xhtml+xml is only recognized by modern browsers and not Internet Explorer.
          Hi drhowarddrfine

          The extra # was careless. I actually sorted the problem by taking the final / from the link field.

          So where do I change text/xml to application/xml? Maybe it's obvious to you but I've only been doing this for a week and not everything is easy yet. And as for really using xml, I've no idea. I got a book called HTML and CSS in 24 Hours by Dick Oliver and Mchael Morrison and took it from there.

          It's real good fun though.

          And sincere thanks for your time.

          Regards

          Jim Walsh

          Comment

          • MrPutty
            New Member
            • Aug 2007
            • 13

            #6
            Hello Jim,

            I'd like to recommend using a directory structure when coding. It'll make life a lot easier on you when projects start to grow. What you'll need for now is:

            - a root directory (helps when you upload your project to a sever)
            - a directory for: html docs, css docs and images.

            possible structure:
            - html
            + - doc
            + - css
            + - img

            Just my two cents on this matter. The HTML code below uses the structure above to link to the stylesheet. href="../css/stylesheet.css"

            you can try this: use the HTML below and fill in your <body> content. Adjust the path to the stylesheet, if needed. Your stylesheet looks fine to me (after drhowarddrfines correction). Try and valdiate your code.

            Hope this works for you!

            Code:
            <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
            <html>
            <head>
            <title></title>
            <link rel="stylesheet" type="text/css" href="../css/bkkcss.css">
            </head>
            <body>
            REMOVE THIS - YOUR CONTENT GOES HERE
            </body>
            </html>

            Comment

            Working...