如何使用 PHP 代码而不是 HTML 代码导入/包含 CSS 文件?
我在谷歌上搜索了很多,但似乎我做错了什么.
I have googled a lot but it seems that I am doing something wrong.
我想这样做:
<?php
include 'header.php';
include'CSS/main.css';
...
?>
但是,我的页面打印了 CSS 代码.
However, my page prints the CSS code.
注意:我想使用 PHP 来包含 CSS 文件,而不是使用我还想将我的 CSS 文件重命名为某些网站提到的 PHP 文件.
Note: I want to use PHP to include the CSS file, and not use I also do you want to rename my CSS file to a PHP file as some website mentioned.
有什么线索吗?
非常感谢.
推荐答案
你必须用 标签包围 CSS:
You have to surround the CSS with a <style>
tag:
<?php include 'header.php'; ?>
<style>
<?php include 'CSS/main.css'; ?>
</style>
...
PHP include
在 .css
结尾也能正常工作.通过这种方式,您甚至可以在 CSS 文件中使用 PHP.这对组织例如非常有帮助.颜色作为变量.
PHP include
works fine with .css
ending too. In this way you can even use PHP in your CSS file. That can be really helpful to organize e.g. colors as variables.
相关文章