【问题标题】:How to include css file in php?如何在php中包含css文件?
【发布时间】:2014-12-07 00:37:36
【问题描述】:

我正在使用 php 文件并想将 CSS 文件包含到 PHP 中,我已包含但它无法正常工作。

我正在执行的文件在这个目录中:

http://host.com/at_t/application/modules/employees/view/employee_detail_view.php?id=4

我想包含以下目录中存在的 CSS 文件

http://host.com/at_t/public/style/style.css

我已经使用代码包含在 PHP 中:

<link href="public/css/style.css" rel='stylesheet'/>

此代码不起作用。请指导我该怎么做?

【问题讨论】:

  • 如果您使用/at_t/public/style/style.css 或完整地址http://host.com/at_t/public/style/style.css 与您正在使用的代码一起使用是否有效。

标签: html css


【解决方案1】:

1) 首先你的代码中有错别字。

根据您的问题,css 文件位于样式文件夹中(http://host.com/at_t/public/style/style.css),但您在链接 href 标记中添加了错误的路径(css/style.css")。

2) 二、

您的employee_detail_view.php 文件存在于视图文件夹中(http://host.com/at_t/application/modules/employees/view/employee_detail_view.php?id=4) 因此,如果您将链接href 设为(css/style.css") 然后它也找不到 css 文件,因为它只在 view 文件夹及其子文件夹中搜索 css 文件.因此,请在链接 href 标记中使用完整地址,如下所示。

它可能会起作用。

【讨论】:

    【解决方案2】:

    也许你没有把正确的路径放到你的 css 文件中?

    <html>
    <head>
    <link href="http://host.com/at_t/public/style/style.css" rel='stylesheet'/>
    </head>
    <body>
    
    ...
    
    </body>
    </html>
    

    【讨论】:

      【解决方案3】:

      将以下 css 放入现有的 html 头标记中。像这样。然后将css标签放入php中:

      <?php //code
       ?>php
      <!DOCTYPE html>
      <html>
         <head>
           <link href="/css/style.css" rel='stylesheet'>
      
      
         </head>
         <body>
              <?php
                echo "<div class='red'>I'm red</div>";
              ?>
          </body>
       </html>
      

      您的 CSS 文件

      .red {
          font-color: red;
      }
      

      【讨论】:

        【解决方案4】:

        这里你只写以下代码。

        <link href="/css/style.css" rel='stylesheet'>
        

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        • 2015-05-11
        • 1970-01-01
        • 2011-03-29
        • 1970-01-01
        • 2011-12-24
        • 2013-05-25
        相关资源
        最近更新 更多