Need CSS tips for my personal site.

Discussion in 'OT Technology' started by dmora, Nov 3, 2008.

  1. dmora

    dmora Guest

    How do i make HTML load random CSS options?
    Like if i wanted to change the color of the outlines and <h#>'s etc.
     
  2. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    Use PHP to pull a random css from a folder of them??
     
  3. owt200x

    owt200x New Member

    Joined:
    Nov 2, 2008
    Messages:
    6
    Likes Received:
    0
    Name your stylesheets in some order, say style1.css, style2.css etc.
    Add this to your php loading code at the top of your page, the 1,5 is how many css files you have, start at 1 end at 5.

    <? $num = rand(1,5); ?>


    then put this after your head but before your body code

    <link rel="stylesheet" type="text/css" href="css/style<? echo $num; ?>.css">
     
  4. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    make one stylesheet as a base, and just write some javascript to change the colors using random numbers

    no reason to add php processing for something dumb like that
     
  5. owt200x

    owt200x New Member

    Joined:
    Nov 2, 2008
    Messages:
    6
    Likes Received:
    0
    its alot easier using what i posted above than using javascript, which can be disabled by the ones looking at your site, php cant be disabled
     
  6. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    but is the overhead of the extra php processing really worth such a trivial gain?

    I guess if you're more concerned with bandwidth than cpu usage, go the PHP route.
     
  7. owt200x

    owt200x New Member

    Joined:
    Nov 2, 2008
    Messages:
    6
    Likes Received:
    0
    actually the code to do this in php is a lot smaller and less complicated than javascript, and i dont know JS

    plus with php and css you can make sure different color schemes dont conflict with each other, using random colors with javascript, you may get a pile of poo for colors, instead of certain schemes.
     
    Last edited: Nov 4, 2008
  8. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    random numbers to randomly pick a stylesheet :uh:

    http://www.alistapart.com/articles/alternate/
     
  9. owt200x

    owt200x New Member

    Joined:
    Nov 2, 2008
    Messages:
    6
    Likes Received:
    0
    not trying to argue with u, just saying using the php code i put above is alot easier than javascript
     
  10. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    The PHP is all executed on the server; all it will do is choose a CSS sheet when the client requests to see the page, and then the page and the chosen CSS file will get sent out to the client.
     
  11. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    yeah..

    just seems wasteful to me to use php to alter presentation when js is perfectly capable

    either will work, though.
     

Share This Page