Jump to content

Change styles based on month?


dropfaith

Recommended Posts

i Know the code below works to change style sheets based on the hour of the day but is there a possible solution to also make it change styles based on the month dynamically..

i want the site to change styles 4 times a year following the seasons  and all i have found so far is by the hour

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getCSS()
{
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();

if (thehour > 20)
display = "tree_twilight.css";
else if (thehour > 17)
display = "tree_sunset.css";
else if (thehour > 14)
display = "tree_afternoon.css";
else if (thehour > 11)
display = "tree_noon.css";
else if (thehour > 7)
display = "tree_morning.css";
else if (thehour > 4)
display = "tree_sunrise.css";
else if (thehour > 1)
display = "tree_twilight.css";
else
display = "tree_sunset.css";

var css = '<';  css+='link rel="stylesheet" href=' + display + ' \/';  css+='>';

document.write(css);
// End -->
}
</script>
<script language="javascript">getCSS();</script>




<noscript>
<link rel="stylesheet" href="tree_sunset.css" type="text/css">
</noscript>

Link to comment
Share on other sites

You don't need javascript to do that.

in the head:

<?php
$seasoncss="";
switch(date("n")){
    case 3:
        $seasoncss="spring.css";
        break;
    case 6:
        $seasoncss="summer.css";
        break;
    case 9:
        $seasoncss="fall.css";
        break;
    case 12:
        $seasoncss="winter.css";
        break;
}
echo "<link rel=\"stylesheet\" href=\"$seasoncss\" type=\"text/css\">";

should be close and will work with javascript turned off.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.