1

I'll include a basic example code; im trying to understand how to add css editing to a php file - within the file. Currently when the webpage opens from the server the editing is not applying.

lets say I want the variable myBirthday in the following code to increase in size and change colour to red, how do i fix this code?

<head>
   <title>
       countdown
   </title>
      <style type=”text/css”>
        #myBirthday
        {
          font-size: 100;
          color: #FF0000;
        }
      </style>

</head>
<body>
    <h1>
      My birthday.
    </h1>
    <?php
        $myBirthday = "10th October 1997";
        echo "Tell you a secret, my birthday is " . $myBirthday . <br> "Today is " .date('d-m-y') . ". <br>";
    ?>
</body>
3
  • 1
    You did not assign the id myBirthday to any element. Please do this and see if it works. Commented Mar 23, 2017 at 18:21
  • You don't add CSS to a PHP file, you add it to HTML Commented Mar 23, 2017 at 18:21
  • change the echo to echo '<p id="myBirthday">...</p>'; You need to assign the #myBirthday ID to an element on the page with your birthday text in it. Commented Mar 23, 2017 at 18:22

1 Answer 1

1

I enclosed the myBirthday variable within a span which I gave the ID myBrirthday in order to style it with the CSS code you provided

<body>
    <h1>
      My birthday.
    </h1>
    <?php
        $myBirthday = "10th October 1997";
        echo "Tell you a secret, my birthday is <span id=\"myBirthday\">" . $myBirthday ."</span> <br> Today is " .date('d-m-y') . ". <br>";
    ?>
</body>

Also note that double quotes must be escaped when inside the "echo" statement.

Sign up to request clarification or add additional context in comments.

7 Comments

Do or do not. There is no "try". A good answer will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO.
you got a point @JayBlanchard and I edited my answer accordingly
Even using this code, there is still no css editing after uploading to server and refreshing link.
i.e. the variable 'myBirthday' is not increased in size or changed in colour as the css code should have made it do.
hmm, kinda confused myself too... I looked at it and seems ok... /)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.