在 .php 文件中包含 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15086785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:32:29  来源:igfitidea点击:

Including CSS in .php file

phpcssincludeinclude-path

提问by user1922212

I am trying to include a css file to my .php file.

我正在尝试将 css 文件包含到我的 .php 文件中。

Inside the .php file, I have;

在 .php 文件中,我有;

<?php
Loads of code..
?>

I'm wanting it like this..

我想要这样..

<?php
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
Loads of code..
?>

But obviously that doesn't work. Is there any way I can do this?

但显然这行不通。有什么办法可以做到这一点吗?

Thanks!

谢谢!

回答by Jesper Veldhuizen

You can use echo..

你可以使用echo..

<?php
echo '<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">';
?>

回答by peter.svintsitskiy

<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<?php
Loads of code..
?>

回答by Patrick Savalle

Uhhhm... You mean something likes this?

呃……你的意思是像这样的东西?

<?php
echo '<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">';
Loads of code..
?>

回答by Step

I have posted a simple solution here : https://navydadon.wordpress.com/2016/02/18/css-in-php-file/hope it will helps :)

我在这里发布了一个简单的解决方案:https: //navydadon.wordpress.com/2016/02/18/css-in-php-file/希望它会有所 帮助:)

回答by HN Singh

The same happened for me a long ago. The best way to solve this is by inserting the css files in all of the files you have included to make your main php page.

很久以前,同样的事情发生在我身上。解决此问题的最佳方法是在您包含的所有文件中插入 css 文件以制作主 php 页面。