www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Change Style Sheet with the seasons

  1. #1
    Join Date
    Jan 2004
    Posts
    7

    Change Style Sheet with the seasons

    Does anyone know a way either through javascript or DHTML to have your style sheets change automatically upon a certain date or season.

    I've seen switchers that work with buttons, and I've seen scripts that can change page backgrounds based on months or seasons, but I cannot find a way to do style sheets automatically.

    WARNING: I'm a beginner, at best, when it comes to javascript. My forte lies in HTML and CSS.

    Any help is greatly appreciated.

  2. #2
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    Since seasons are the same for everyone do it server side.

  3. #3
    Join Date
    Jan 2004
    Posts
    7
    If I don't know javascript, that still doesn't solve my problem. It doesn't matter, server side or client side, if I don't know what it takes to do it.

    So does ANYONE ELSE have any ideas?

    Thanks.

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Here's a simple style changer in PHP: http://forums.webdeveloper.com/showt...4661#post77670

  5. #5
    Join Date
    Jan 2004
    Posts
    7
    Okay... I sort of understand what that PHP script does, but how can I get it to work for seasonal changes? I'm putting together a website for a client that wants to run seasonal specials for their merchandise. I've designed the entire page using style sheets instead of tables and when the season's change (approx - know it don't be to the minute exactly) I want the script to call the proper style sheet.

    Again, though, scripting languages aren't my strong suit. Explain it to me as though I were an idiot...okay, maybe not an idiot but you get the picture.

  6. #6
    Join Date
    Mar 2003
    Location
    Escondido, CA
    Posts
    998
    I think all you need to do with that script is to divide 31536000 by 4. That will give you a new style every 4 months.

    31536000
    / 4
    -----------
    7884000

  7. #7
    Join Date
    Jan 2004
    Posts
    7
    Pretty smart idea. You're way ahead of me on that one. I'll give it a try. Thanks.

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Actually, that will just allow the cookie to expire. The original script was meant to be used to allow users to change their stylesheets. If you want to load a different stylesheet based on the time of year, it would be much easier, as all you'd have to do is use PHP's date() functions to get the current month and display the corresponding stylesheet.

  9. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Here's the gist of what I'm talking about. Some tweaking would give you better results if you are looking to base it on seasons, though.

    PHP Code:
    <?PHP
    $month 
    date("n"); # get month (1-12)
    if ($month 4) { # 1-3
        
    echo "first stylesheet";

    else if (
    $month && $month 7) { # 4-6
        
    echo "second stylesheet";
    }
    else if (
    $month && $month 10) { # 7-9
        
    echo "third stylesheet";
    }
    else { 
    # 10-12
        
    echo "fourth stylesheet";
    }
    ?>

  10. #10
    Join Date
    Jan 2004
    Posts
    7
    Thanks again.

  11. #11
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You bet.

  12. #12
    Join Date
    Nov 2002
    Posts
    2,632
    I have a somewhat unrelated question. Let's say I have two stylesheets and after the user picks the second one, will there be a slight, but noticable change in the layout as it goes from the default layout to the newer one if you use a PHP style sheet switcher? I ask because I have gone to meyer's website and picked different style sheets only to see this switch like effect happening. I know his style sheet switcher is done via JavaScript. I also have a 56K connection so page loads will be slower than for a high speed connection.

  13. #13
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    No, there shouldn't be. You can see a demo of the PHP version running at http://www.webdevfaqs.com/. The only thing you will be likely to notice would be images loading...

  14. #14
    Join Date
    Dec 2003
    Posts
    82
    Originally posted by Vladdy
    Since seasons are the same for everyone do it server side.
    am i interpreting this wrong or did you mean that when it is Winter in England, then it is Winter in Australia?

    that's a bit wrong aint it?

    ah well!

  15. #15
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Originally posted by giggledesign
    am i interpreting this wrong or did you mean that when it is Winter in England, then it is Winter in Australia?

    that's a bit wrong aint it?

    ah well!
    Nah, them Aussies just have hot Winters down there.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles