SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linking CSS to a Web Page - can't make it work

    In the "Build Your Own Web Site The Right Way Using HTML & CSS" book, I've hit a snag in Chapter 3 in the 'Linking CSS to a Web Page' section. Despite following instructions to the letter in creating the CSS style file and inserting the links on the three web pages, the style (boldface, blue font paragraphs) is not displaying on the pages in my web browser (which is Safari). I've created the CSS style sheet file and inserted the link element to each web page exactly as explained. I even checked the html code for the chapter that I downloaded for the book and it matches exactly.

    Is there something elemental that I could be missing?

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Welcome to SitePoint Forums, sfromhart!

    We can't be of much help with so little concrete information, but here are some things you might want to look at:

    Is the HTML syntactically correct? You can use W3C's HTML validator to check it.

    Is the path to the CSS file correctly specified in your <link> elements? Check the spelling and capitalisation, and make sure you use forward slashes ('/') as path separators, if there are any, not backslashes ('\'). For example,

    <link rel="stylesheet" type="text/css" href="style/myStyle.css" media="screen">

    For this link to work, the CSS style sheet file must be named 'myStyle.css' and reside in a subdirectory named 'style'. If the file name is 'MyStyle.css' or 'myStyle.CSS' it may not work (depends on your operating system).

    Is the CSS syntactically correct? You can use the W3C CSS validator to check it.

    Do the selectors in your CSS style sheet match any elements in your HTML documents? For instance, if you've used an ID selector like #foo, is there an HTML element width id="foo" to affect?
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm embarrassed to say that I was indeed missing an essential item in my markup. A SitePoint rep asked me to send him my files and he found that I was missing an end-quote in my meta tag. Interesting that it wasn't big enough to stop the page from showing up until now, but it was enough to prevent my CSS link from linking to my style guide. He explained that html will power through some little mistakes, but eventually it will catch up to me. I'm learning. Here's what I had written:

    <meta http-equiv="Content-Type"
    content="text/html; charset=utf-8/>

    Once I put an end-quote before the /> everything worked. Thank you, AutisticCuckoo for replying to this post. I'm sure you would have caught it also, if you'd seen my html markup.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm glad you found the problem. We all make mistakes like that from time to time.

    That's why W3C's HTML validator is your best friend.

    If something isn't working, the first thing you should do is to run it through the validator to see if there are any errors. As you found out, even very trivial ones can have a significant effect. Only when you're satisfied that the markup is correct should you attempt other forms of trouble-shooting.

    That's my advice, any way.
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the W3C validator has saved me so many times! Also download firebug for firefox, its very helpful!

  6. #6
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks AutisticCuckoo. That sounds like great advice. The SitePoints team also recommended that I use TextWrangler, which has syntax coloring, so hopefully that will help me, also. Thanks again for the support.


Bookmarks

Posting Permissions

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