【问题标题】:How to add css file in PHP? [closed]如何在 PHP 中添加 css 文件? [关闭]
【发布时间】:2018-11-16 01:13:13
【问题描述】:

我想在 php 中包含我的 css 文件,有人可以帮我添加吗?

 include('config.php');
 $cssFile = "style.css";
 echo "<link rel='stylesheet' href='/books/style.css'>";

如何在 PHP 应用程序中添加我的 css?

【问题讨论】:

  • 我必须文件 1 php 和 2 是 css ,我想在 php 页面中设置一些样式,我该怎么做?
  • 您期望的结果是什么?你想完成什么?

标签: php css


【解决方案1】:

我在生成 pdf 时使用外部 css 文件,它对我有用。

试试这个。

$stylesheet = '<style>'.file_get_contents('path/style.css').'</style>';

【讨论】:

    【解决方案2】:

    考虑到您的 PHP 以 &lt;?php&lt;? 标记开头,您可以将 CSS 添加到 php 文件的顶部(如果您通过 php 发送标头,则在某些行之后)从 php 标记中添加。

    不要忘记样式适用于 HTML 代码,因此它需要脱离 PHP。 如果你的 PHP 生成 html 代码,你也可以在那里使用普通的 CSS。

    例子:

    <html>
    <head>
    <link rel='stylesheet' href='/books/style.css' type="text/css">
    </head>
    <body>
    <?php
    include('config.php');
    //your php code here
    ?>
    </body>
    </html>
    

    【讨论】:

      【解决方案3】:

      已经问过并回答过。请务必先搜索谷歌。我已经找到了很多教程和答案:)。 我最喜欢这个:https://stackoverflow.com/a/6315792/1015712.

      这里有完整的问答:How to import/include a CSS file using PHP code and not HTML code?

      那是 6 年前的事了,但我认为较新的 PHP 版本没有改变这一点。

      【讨论】:

        猜你喜欢
        • 2018-06-27
        • 2015-04-03
        • 2020-11-18
        • 1970-01-01
        • 2013-04-21
        • 1970-01-01
        • 1970-01-01
        • 2015-02-12
        • 2012-11-29
        相关资源
        最近更新 更多