Perhaps the return value of base_url()
does not end in the path separator.
With that in mind, try this:
@import url("<?php echo base_url().'/public/';?>css/layout.css");
(Notice the slash before "public")
- Check the source of the page via your browser's "view source" or similar, and check if the path in the
@import
is correct
or
- Use a request logger similar to Chrome's devtools' "network" tab to see what URL your browser is trying to load the imported CSS file from.
You also view the CSS via your browser to identify whether the contents are being correctly built. If you see <?php
inside the response, you'll need to make Apache treat the CSS file as if it was PHP.
You can add something similar to the following into your .htaccess file:
<FilesMatch "\.css$">
SetHandler application/x-httpd-php
Header set Content-type "text/css"
</FilesMatch>
You should ensure that the "mod_headers" Apache module is enabled to allow the use of the Header
directive.
Although, personally I would rename such dynamic stylesheets to have a .php.css extension. This will have no effect, but then Apache can be configured to only pass the dynamic stylesheets to the PHP preprocessor.
<FilesMatch "\.php\.css$">
SetHandler application/x-httpd-php
Header set Content-type "text/css"
</FilesMatch>