0

I've got a basic PHP script embedded in a html document. I've also got an external style sheet. When I view the page, the CSS has an effect on the entirety of the page, except on an echo statement. When I test the page with some html text, the CSS works on that, yet it doesn't work when printing the variable.

This is the html/php:

<div id ="date"> 
test
<?php 
echo "$newDate"; 
?>
</div>

This is the CSS for "date":

#date {
color:#ff0000;
}

As I said, the CSS works for the rest of the page, and works when showing "test", as shown below:

css not working

The date "2016-03-15 15:43:40" should also be in red and centered, so why does this not work? Thanks

EDIT: I've got other classes in my CSS (is that the right word?) that format the area outside of this. Could this be affecting my date div tag? Also can I say thanks to all you guys, you're life savers to a beginner like me!

tomandco
  • 51
  • 2
  • 10
  • 3
    Use your browsers inspection panel (right click -> inspect element) to see what's going on – JimL Mar 18 '16 at 21:40
  • 2
    Is there any markup wrapping `$newDate`? – Jesse Kernaghan Mar 18 '16 at 21:40
  • This is your actual code? If i reproduce this, it works. I guess you have different markup or style, because it's weird and the date should be in the same row as the "Test" text and aligned to the left.. – JP. Aulet Mar 18 '16 at 21:43
  • There's nothing in what you've posted which would indicate *why* the date is not red. There must be some other item in your CSS, PHP, or markup that is causing the issue. – Scott Mar 18 '16 at 21:53

2 Answers2

-1

For CSS to take effect the content must be within tags:

echo "<span class='subheading'> hello </span>";

Will output :

<span class='subheading'> hello </span>

Which can be styled with the following CSS:

span.subheading{… … …}

In the echo statement note the use of alternating double and single quotes to prevent the string closing too early. They can be used the other way round if you want your html to have the other kind of quotes.

Arif Burhan
  • 507
  • 4
  • 12
-3

Use:

echo <<< EOT
<div id ="date"> 
    test
    $newDate

</div>
EOT;
rui404
  • 75
  • 1
  • 11