I am looking to introduce PHP variables to stylesheets (ie. CSS).
I have worked out that I can print a PHP page as a stylesheet by declaring:
header(\'Co
You do this the same way you would with HTML:
<?php
header('Content-Type: text/css');
$css = $_GET['css']; // or wherever your're initializing the variable from...
?>
body {
<?= $css ?>border-radius: 3px
}
But, I don't think this is necessary for your use case. It's actually not uncommon to just statically include all the various -*-
options in a css file:
body {
-moz-border-radius: 3px;
border-radius: 3px;
}
Just add all effective options, and the browser will determine which are most effective for it. This also means you get to avoid the dull and error prone task of browser sniffing.
If you just want to be able to use variables in your css (not necessarily php), you could consider using less
SASS CSS extension would allow you to use variables without actually needing to use PHP and the downsides that come with it. Mixins would simplify the generation of vendor-specific style rules.
@mixin vendor-prefix($name, $argument) {
-webkit-#{$name}: #{$argument};
-ms-#{$name}: #{$argument};
-moz-#{$name}: #{$argument};
-o-#{$name}: #{$argument};
#{$name}: #{$argument};
}
p {
@include vendor-prefix(hyphens, auto)
}