Results 1 to 4 of 4

Thread: Can I set CSS to a timer that will exchange itself with another .css file?

  1. #1
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can I set CSS to a timer that will exchange itself with another .css file?

    For my website I would like to have a night and day version. Depending on when you visited the site depended on which CSS showed. I know there are ways where you can manually choose which CSS is showed on your site, but I would like this to be completely automatic.

    I have no idea how I am going to go about doing this. I would at least like to know if anyone has done this, has seen this done anywhere, or has even heard of such an idea? If anyone has an answer to this I would be absolutely greatful!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I've never seen; nor heard of it being, done before, but the idea should be easy enough to do. It just depends on if you want to use Javascript or a server side (PHP, ASP, etc) language to accomplish it. If you wanted to use PHP, the basic idea would be something like this (Placed between the head tags of the document:

    Code:
    <?php
     if (date('H') >= '08' && date('H') <= '19' ) { //if between the hours of 8am and 7pm, show day css
    ?>
     <link rel="stylesheet" href="day.css" type="text/css">
    <?php
     }
    
     else {
    ?>
     <link rel="stylesheet" href="night.css" type="text/css">
    <?php
     }
    ?>
    Not sure how you would accomplish using Javascript, but I do know that it can be done.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have seen it done by a guy who took a photo out of his studio windows for a few times a day and then had his css file change depending on the time of day so people knew what time it was at his location. I hope that makes sense, I'm not the best person for explaining what I'm thinking!

    Anyway, I couldn't find it for you to ask him about, but instead found exactly what your after, I think:

    http://sonspring.com/journal/time-sensitive-css

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The idea seems to be interesting but have to address one more thing for example if a user opens the page in the day session and closes only at night, in this case have to change the day session CSS to night session CSS automatically.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •