Re: Can you use php in an external css file?



On Jun 28, 3:06 pm, Leoa <leondria.bar...@xxxxxxxxx> wrote:
I haven't found any answers on this but is it possibile use php in an
external css file, for example:

// mystyle***.css////

.navbg{background-image: url(<?php echo("<?=$img_dir?>")></?php>/
images/Nav_Background.gif);

}

//////<?=$img_dir?> is a url

Sure -- provided that you use proper PHP syntax (which the above is
not). You'll also likely need to name the file with a .php extension
so the web server parses it as such (it's also possible to configure
your web server to parse .css files through PHP, but I wouldn't go
that route).

You should also (you might even need to) put the following at the top
of the file:

header('Content-type: text/css');

.


Quantcast