CSS dynamically changing advice

Just trying to get a sense as to how I could go about this.

I have a css rule called .textcolor { color: #333; } and in my page it is obviously called with <p class="textcolor">My Text</p>

What if I wanted to change tht colour depending on a condition, so lets say the user has just visited a page called blue.php then navigated from there to this page, I want that user to see all the text in blue, and if they were on the page red.php and navigated to this page then i want all the text to be red. If they just came from any other default page then it must remain dark grey.

How do I go about trying to handle this based upon the route they took to get to the page.

I am kind of thinking about css variables, and a session cookie storing a value that does not get reset unless certain pages are visited.

Community Page
Last updated: