Vissie
Vissie

Reputation: 777

Changing CSS with PHP?

Picture to get understanding of my question!

So, this is the site I made for fun and It's a little dice game where you can guess the outcome of the dice. Anyways, as you can see there is a border under the other div. That's where the output comes from the dice game.

After rolling the dice.

So my question is:

Is there a way to make the CSS style before doing the 'game' different than after playing the game? (Border width: 0px; before and 1px after) Or is there a better way to do this instead of changing the CSS??

Edit by Martijn: The code given in the question makes to question obfuscated and didn't really need to be added. IMO it decreased the value of this question.

Upvotes: 0

Views: 121

Answers (2)

Martijn
Martijn

Reputation: 16103

Yes, but first no: PHP can not change css. PHP is serverside, meaning it's build on a server and the result gets send to your browser. CSS styles the htmlpage on your computer, your computer´s browser calculates how big everything should be etc.

You can however, add a class to the html, depending on the result. This class can be styles.

You have not provided code, so´ll write you a small demo.

$indicationClass = ""; // not good or bad, so no class
    if( $Guess=="correct" ){ $indicationClass = "CorrectAnswer"; }
elseif( $Guess=="wrong" ){   $indicationClass = "WrongAnswer";   }


<div id="ImTheResultDisplayer" class="<?=$indicationClass;?>">
    The color of my text will change!
</div>

This isn't perfect code, but it does demonstrate my point.

If this is done via AJAX or Javascript (meaning the page never refreshes, you can use the same principle.

Upvotes: 4

Mirdrack
Mirdrack

Reputation: 790

There is no way to modify your CSS with PHP

Try to learn Javascript add "movement" and other things to your web page, this language allows you to modify the style of your website after this is served by the server

Its a long way on web development but I wish you luck

Upvotes: -1

Related Questions