Skip to content

Timed style sheets in PHP and ASP

You may or may not have noticed that my site has a timed style sheet. Visit the site during the day and it has a day theme, early evening a sunset theme and during the night a night theme (you can also click the icons at the bottom left of the site to view each theme). I often get emails asking how it’s done. It’s very simple, and here’s how.

Please do check out their sites do see how it’s done and thanks for the refferal guys.

The basics

How the timed style sheets are achieved is very simple. Basically I have three style sheets entitled day.css, sunset.css & night.css. The code checks to see what time it is and if it is between 7am and 5pm, the output is day.css. Between 5pm & 8pm sunset.css and 8pm & 7am night.css. That’s all there is to it.

PHP

<link rel="stylesheet" type="text/css" href="<?php $hour = date("H"); if ($hour >= 7 and $hour < 17) echo "day.css"; elseif ($hour >= 17 and $hour < 20) echo "sunset.css"; else echo "night.css"; ?>" />

ASP

<link rel="stylesheet" type="text/css" href="<%if time >= #07:00# and time <= #17:00# then theme = "day.css" elseif time > #17:00# and time <= #20:00# then response.write "sunset.css" else response.write "night.css" end if%>

CSS themes

Want to read more?

    None related articles found

Psst! We're hiring an Interaction Designer at Kareo. Click here if interested.

Photo of Lee Munroe

Written by Lee Munroe.

Follow @leemunroe on Twitter for more articles on UX design.


5 Appreciated Comments

Add your comment

  1. Harry Roberts says:

    Hi Lee, thanks for the props! The ASP version looks pretty similar, I have no ASP knowledge, how easy is it to learn? Harry

  2. lee says:

    No problem Harry. Both very similar in regards to structure but PHP syntax is more C++ based where as asp is very visual basic like and runs on IIS. I think if you know one it wouldn’t take long to learn the other. Would recommend learning asp.NET over asp as it’s the most recent and apparently a lot more powerful.

  3. Harry says:

    Cool, I might take a look at it!

  4. ?? says:

    ??????????????~

  5. Harry says:

    Lee, found another site which uses timed css: http://www.mariusroosendaal.com/. Quite nice I think you’ll agree.