PDA

View Full Version : echo css



ggalan
06-28-2010, 07:42 PM
how can i echo out css, i tried this but it didnt call the css


<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>

bluewalrus
06-28-2010, 08:31 PM
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.

ggalan
06-28-2010, 08:50 PM
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??

bluewalrus
06-28-2010, 09:20 PM
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.


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


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.

ggalan
06-28-2010, 10:09 PM
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/">

Schmoopy
06-28-2010, 10:22 PM
You could also go for this, which means you won't have to escape quotes and is more easily readable:



<?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
}
?>

ggalan
06-29-2010, 12:08 AM
so you dont have to echo the lines??
why is that last "/" so important?

bluewalrus
06-29-2010, 01:13 AM
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.