如何在css文件中使用PHP [英] How to use PHP inside css file
本文介绍了如何在css文件中使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有CSS文件,我想用PHP可变格式在该文件中引用一些图像路径。然后我将这个css文件引用到html文件中。以下是我的文件
CSS文件
<标题(Content-type:text / css);?>
body {margin:0px;字体:9px / 11pxTahoma,Arial,Helvetica,sans-serif;颜色:#010000;
background:#f3f6e1 url(<?php echo base_url()。'public /';?> images / body_bg_1.gif)repeat-x 0 0}
HTML档案
< html xmlns = http://www.w3.org/1999/xhtml\">
< head>
< link rel =stylesheethref =css / layout.cssmedia =screen>
< / head>
其他的事情。你可以解释一下如何做到这一点吗? 解决方案
如果你能够重命名你的CSS文件layout.php,没有必要采用所有这些解决方法:
您的layout.php文件应该是这样的:
<?php header(Content-type:text / css; charset:UTF-8); ?>
body {margin:0px;字体:9px / 11pxTahoma,Arial,Helvetica,sans-serif;颜色:#010000;
background:#f3f6e1 url(<?php echo base_url()。'public /';?> images / body_bg_1.gif)repeat-x 0 0}
您的HTML档案看起来像:
< ; html xmlns =http://www.w3.org/1999/xhtml>
< head>
< link rel =stylesheethref =css / layout.phpmedia =screen>
< / head>
这个问题非常相似:包括:css和php文件扩展名?
I have CSS file and I want to refer some image paths in that files in PHP varaible format. Then I refer that css file inside a html file. Following are my file
CSS file
<? header ("Content-type: text/css");?> 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}
HTML file
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="css/layout.css" media="screen"> </head>
Other things. Can you explain me how to do this ?
解决方案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?
这篇关于如何在css文件中使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文