php in css?

  • Tazel
  • Student
  • Student
  • Tazel
  • Posts: 97

Post 3+ Months Ago

Can you use php in css? Like for seasons, I'm thinking of being able to change the colors with one variable. So can you?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

You can't use it in a .css file, but if you were to type the css in the page, then you simply have to have a php tag where you want it to go. You can also do it inside of a tag like:
Code: [ Select ]
<?
echo ("<b style='$var'>");
?>
  1. <?
  2. echo ("<b style='$var'>");
  3. ?>
  • Tazel
  • Student
  • Student
  • Tazel
  • Posts: 97

Post 3+ Months Ago

Well currently, I'm linking it through to the page it's being used by via <link>. But, I think I have a solution. What if I make the page php, and echo everything through to make it look just like a css declaration in a regular page? Will linking this file compared to linking just a css file have any differences like a major one: speed?
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

A bit, because instead of just reading a file, the server has to parse
through all of the php (still not long, we are talking tenths of a second).

I would recommend, if you are only doing it for a few class's, to override
the included stuff with a style atribute in the link's tag, or even in the header.

You could also make several .css files and call the one for the right season
with php.

I like your idea by the way, I wanted to theme a webpage with a
daytime/nightime theme, and it would change accordingly.
  • rjmthezonenet
  • Expert
  • Expert
  • User avatar
  • Posts: 526
  • Loc: St. John's, Newfoundland, Canada

Post 3+ Months Ago

b_heyer wrote:
You could also make several .css files and call the one for the right season with php.

I like your idea by the way, I wanted to theme a webpage with a
daytime/nightime theme, and it would change accordingly.


For something that changes as often as a day/night theme, go with different external style sheets and use PHP to print out the appropriate LINK tag.

For something less often, like seasons, point all your pages to something.css and keep copies of your special style sheets under different names. Overwrite something.css with the stylesheet du jour. No need to script every page if that is all you're doing...

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 41 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.