Treehouse: Grow your CSS skills. Land your dream job.

[Solved] Adding a DOCTYPE killed my PHP Variable CSS

  • # March 19, 2010 at 2:07 pm

    I am presently working on a website for which I had declared no DOCTYPE. Of course it was impossible to validate the HTML without a DOCTYPE, so I added one (HTML 4.01 Transitional). The HTML now validates and the CSS validates as CSS2.1. However, before adding the DOCTYPE the site worked across all the browsers I tested (IE8, Firefox, Chrome, Safari) and now it only works for IE. All other browsers completely ignore the CSS.

    Does anyone have any ideas?

    Here is the original page without a DOCTYPE:

    Here is the identical page except for the addition of a DOCTYPE:


    # March 19, 2010 at 3:00 pm

    you are calling your stylesheet in as a PHP file – so I am guessing you want to use variables or something in your CSS?

    If you have done this you need to make sure you set your headers in your style.css


    < ?php
    header("Content-type: text/css");
    $color = "green"; // <--- define the variable
    echo << /* --- start of css --- */
    color: $color; /* <--- use the variable */
    font-weight: bold;
    font-size: 1.2em;
    text-align: left;
    /* --- end of css --- */

    If not it wont know what to do with the file.

    # March 19, 2010 at 4:09 pm

    in the CSS link, should be

    # March 20, 2010 at 1:23 am

    Rob, you were correct on all accounts. I am using variables inside my CSS and adding the header to the style sheet has corrected all the problems. Thank you, sir, for your help in my hour of confusion.


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.