PDA

View Full Version : PHP and CSS problem



Adina
April 23rd, 2009, 12:10 PM
I have put this code on a web page :



<p id="thisDay">


<?php
$thisMonth = date(r);
echo $thisMonth;
?>


</p>



The output on the page is this:

Thu, 23 Apr 2009 13:00:07 +0200

Now the problem is that I want to change the color of the text output.




Here is the css code:


#thisDay {
color:darkviolet;

}


The fonts don't change color.. can anyone please tell me what I'm doing wrong?

Peter76
April 23rd, 2009, 02:39 PM
You must have made a typo I guess... When I tried it worked fine. Here is the code I used:



<html>
<head>
<style type="text/css">
#thisDay { color: darkviolet; }
</style>

</head>

<body>
<p id="thisDay">
<?php
$thisMonth=date(r);
echo $thisMonth;
?>
</p>
</body>
</html>


Hope this helps. Good luck

Adina
April 23rd, 2009, 05:42 PM
Thank you for your reply. I canged it to class instead of id and now it works.. so I think maybe there's some problems with my css file. I don't know. But thank's again for your help, I really appreciate it!

Reiger
April 23rd, 2009, 06:48 PM
Or maybe the PHP code outputs more than 1 element with ID "thisDay"?

odyniec
April 23rd, 2009, 07:22 PM
Or maybe the PHP code outputs more than 1 element with ID "thisDay"?

That's not likely to be the cause. While it's wrong to have more than one element with the same ID, I think pretty much every browser would still apply the style to all the elements.

tturrisi
April 25th, 2009, 03:08 PM
Or maybe the PHP code outputs more than 1 element with ID "thisDay"?

PHP doesn't output elements unless the html tags exist within the php echo. PHP just spits out the variable as echoed text w/ no markup or style applied.

Reiger
April 25th, 2009, 08:14 PM
Well yes: but webbrowsers are, as per W3C specs, required to *ignore* ID's which already exist elsewhere in the document. Which means that if multiple tags with the id="thisDay" were output only at most 1 tag should see #thisDay CSS applied.