本文介紹了如何使用 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.
這篇關于如何使用 PHP 代碼而不是 HTML 代碼導入/包含 CSS 文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!