【问题标题】:Apache2: CSS not loading when the file is in another folderApache2:当文件位于另一个文件夹中时,CSS未加载
【发布时间】:2020-02-07 17:15:51
【问题描述】:

问题是我的 CSS 没有加载。

我有一个文件夹 /var/www/example,其中有我的 index.php 和另一个文件夹资产,我有文件夹 /css

在我的 index.php 中,我像这样链接了 css:

<link type="text/css" href="/assets/css/style.css" rel="stylesheet">

但是当我将 style.cssindex.php 一起放入 /var/www/example 并将我的代码更改为 href="style.css 有效!!

我正在使用 Apache2

【问题讨论】:

  • 您正在使用 CSS 文件的根相对路径,并且可能 /example 是一个根文件夹,因此您需要 /example/assets/css/style.css 或者如果您想链接 CSS 文件,可以尝试 href="assets/css/style.css"相对于索引页的位置
  • @MonkeyZeus 我试过了,还是有同样的问题
  • index.php 文件的 URL 是什么?是http://localhost/example/index.php吗?
  • 另外,您的 CSS 文件的完整路径是什么?
  • @MonkeyZeus 当我输入localhost/example/index.php 我没有找到页面,但是当我输入 localhost/ 我有我的 index.php

标签: html css apache2


【解决方案1】:

根目录是example,所以你必须把/example放在assets之前链接应该像下面的例子,另一个想法是删除assets之前的/,因为它不是@ index.php 文件的 987654326@(即目录)。

 &lt;link type="text/css" href="/example/assets/css/style.css" rel="stylesheet"&gt;

【讨论】:

  • 读取cmets,访问index.php时不使用/example
猜你喜欢
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
相关资源
最近更新 更多