我在谷歌上搜索了很多,但似乎我做错了什么.
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.
这篇关于如何使用 PHP 代码而不是 HTML 代码导入/包含 CSS 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)