DotDragnet
May 23, 2012, 04:20:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: CSS with some PHP sprinkles?  (Read 735 times)
Ben
Hero Member
*****
Posts: 766


I didn't do it


View Profile Awards
« on: January 24, 2010, 05:48:16 PM »

I've got a site that I'd like to do throw a random (from a predetermined set) colour to the stylesheet to change certain elements - i.e. link colour, H1 color etc on a reload.

My thought was to have the colour stored as a variable, then reference the colour in the CSS so it only actually changes one line each time.

So... if I make my .css file to a .php file and add this at the top:

Code:
<?php header("Content-type: text/css"); ?>

Is this bad practice or not advised?

<cheeky> Me being a total PHP noob 101: Does anyone have an example of PHP that randomly selects from a list of variables per reload? </cheeky>
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 550



View Profile Awards
« Reply #1 on: January 24, 2010, 07:05:54 PM »

That would work. Although in the interests of efficiency I'd suggest one style sheet with the bulk of the css and a second with only the variable line.


Quote
<cheeky> Me being a total PHP noob 101: Does anyone have an example of PHP that randomly selects from a list of variables per reload? </cheeky>

array_rand().
Logged
suedenem
Sr. Member
****
Posts: 410



View Profile Awards
« Reply #2 on: January 25, 2010, 09:21:45 AM »

As an aside, you don't need to rename your *.css - if you're using Apache, for example, you can force CSS files to be parsed as PHP by adding something like this to your .htaccess file:

AddType application/x-httpd-php .css

It saves renaming files, stops you having to edit the file's URI and makes the URI future-proof - just because you're using PHP now it doesn't mean you will in 5 years time.
Logged

So this SEO copywriter walks into a bar, grill, pub, public house, Irish bar, bartender, drinks, beer, wine, liquor...

Beware my weird, cross-dressing comment's; they are pretty standard examples of trolling.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!