Is there any reason you should not use PHP to overcome some of the shortcomings of CSS? Live inspection would be harder but are there any functional downsides?
5 Answers
Yes, it's great to preprocess CSS somehow. But do not invent a wheel. There are lots of "standard" options to use:
- Sass http://sass-lang.com/
- Turbine http://turbinecss.org/
- Pornel http://pornel.net/css
- Less http://lesscss.org/
- more, just search.
Comments
The only downside I can think of is server processing power and lack of easy caching of CSS files.
Other then that (both can be remedied) it's perfectly acceptable.
3 Comments
Have you looked at one of the precompiled css languages like LessCss or Sass?
Comments
It's really a matter of preference as well as the requirements of your specific situation. The main argument against mixing programming with CSS is that it complicates something that was specifically designed for non-programmers to be able to do.
If you use php within css you've limited that file to run only through php so you lose compatibility.
There are plenty of tools out like SASS that are designed for making css more powerful.
Personally I like to put color values into php variables so I can be sure to get them right and so I can re-skin later. Other than that I keep it clean.
Comments
I think it is a fine idea, and if you know PHP already it will be easier than learning a new syntax, such as sass/less, etc.
Unless it is a toy site I would not recommend creating the css on the fly with each request. Instead create a script that builds the css files from templates every time the server starts up, or to a schedule most useful to you.
More sophisticated still would be using something like make to only build them when the input templates have changed.