How to use PHP inside css file

If you’re able to rename your CSS file “layout.php”, there’s no need for all of these workarounds:

Your layout.php file would look like:

<?php header("Content-type: text/css; charset: UTF-8"); ?>
body{ margin:0px; font:9px/11px "Tahoma", Arial, Helvetica, sans-serif; color:#010000; 
background:#f3f6e1 url(<?php echo base_url().'public/';?>images/body_bg_1.gif) repeat-x 0 0}

Your HTML files would look like:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/layout.php" media="screen"> 
</head>

This question is very similar: Include: css with php file extension?

Leave a Comment