Results 1 to 8 of 8

Thread: echo css

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default echo css

    how can i echo out css, i tried this but it didnt call the css
    Code:
    <head>		
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    <title></title>
    <?php
    if ($subcat == "4") {
    echo '<style type="text/css/">',"\n";
    echo ".navLine4 a:link {text-decoration:none; color:#979899;}","\n";
    echo ".navLine4 a:visited {text-decoration:none; color:#979899;}","\n";
    echo ".navLine4 a:hover {text-decoration:none; color:#979899;}","\n";
    echo ".navLine4 a:active {text-decoration:none; color:#979899;}","\n";
    echo "</style>";
    
    	}
    
    if ($subcat == "5") {
    echo '<style type="text/css/">',"\n";
    echo ".navLine5 a:link { text-decoration:none; color:#979899; }","\n";
    echo ".navLine5 a:visited { text-decoration:none; color:#979899;}","\n";
    echo ".navLine5 a:hover { text-decoration:none; color:#979899; }","\n";
    echo ".navLine5 a:active { text-decoration:none; color:#979899; }","\n";
    echo "</style>";
    
    	}
    ?>	
    
    </head>

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Where are you setting subcat?

    That says if subcat is 4 does this style. if subcat is 5 do this style. In what you've posted neither of these are met so neither style will be selected.
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i didnt want to clutter the code box but it outputs the css. the only problem is that it doesnt seem to respond. i have other pages that are static and this css code works, its just that when its on a dynamic template, the css outputs but doesnt seem to do anything

    any suggestions??

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Try changing your css tag to <style type="text/css"> from <style type="text/css/">.

    If the css is on your page this could be the problem...

    If not we'd need to see more of the code because that's the only problem I see you also don't need all those echos but that shouldn't affect the output just the processing.
    PHP Code:
    echo '<style type="text/css/">',"\n" .".navLine4 a:link {text-decoration:none; color:#979899;}","\n" .
     
    ".navLine4 a:visited {text-decoration:none; color:#979899;}","\n" ".navLine4 a:hover {text-decoration:none; color:#979899;}","\n" ".navLine4 a:active {text-decoration:none; color:#979899;}","\n"
     
    "</style>"
    or even

    PHP Code:
    echo "<style type=\"text/css\">\nnavLine4 a:link {text-decoration:none; color:#979899;}\n.navLine4 a:visited {text-decoration:none; color:#979899;}\n.navLine4 a:hover {text-decoration:none; color:#979899;}\n.navLine4 a:active {text-decoration:none; color:#979899;}\n</style>\n"
    the double quotes in the style element have the extra slashes to escape the opening echo double quotes.
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    awesome! thank you
    it was that extra "/"

    this did it, Try changing your css tag to
    <style type="text/css">
    from
    <style type="text/css/">

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You could also go for this, which means you won't have to escape quotes and is more easily readable:

    PHP Code:
    <?php
    if ($subcat == "4") {
    ?>
    <style type="text/css">
    .navLine4 a:link {text-decoration:none; color:#979899;}
    .navLine4 a:visited {text-decoration:none; color:#979899;}
    .navLine4 a:hover {text-decoration:none; color:#979899;}
    .navLine4 a:active {text-decoration:none; color:#979899;}
    </style>
    <?php
    }
    ?>

  7. #7
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    so you dont have to echo the lines??
    why is that last "/" so important?

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    If by "/" you meant "}" that closes the php if statement. It's easier to think of it as a block, anything within the block will be executed when the condition is met. It doesn't matter if it is php, html, css, javascript, etc. If it is not php you can end the php as schmoopy has done and then re-open the php so the php knows where the if ends then close the php as well.
    Corrections to my coding/thoughts welcome.

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
  •