CSS 不能从相对路径与 php 'includes' 一起使用 [英] CSS not working from relative path with php 'includes'
问题描述
文件夹结构
/
|--index.php
+--includes
|--header.html
+--css
|--style.css
我的主项目文件夹中有 2 个子文件夹.一个是名为includes"的文件夹,另一个名为css".我有我的-index.php
主文件夹中的文件-header.html
在我的 'main/includes'
文件夹中-style.css
在我的 'main/css'
文件夹中
I have 2 subfolders in my main project folder. One is a folder called 'includes' and the other one is called 'css'.
I have my
-index.php
file in the main folder
-header.html
in my 'main/includes'
folder
-style.css
in my 'main/css'
folder
我的 index.php 包含这样的 header.html:include_once('includes/header.html');
(这个作品!)
My index.php includes the header.html like this:include_once('includes/header.html');
(this Works!)
我的 header.html 文件像这样链接 css:<link href='../css/style.css' type='text/css' rel='stylesheet'/>
(这不起作用!)
My header.html file links the css like this:<link href='../css/style.css' type='text/css' rel='stylesheet'/>
(this does NOT work!)
我不明白为什么没有加载 css 文件.
我曾尝试使用基本标签,但我不确定我是否正确使用它.<base href="http://localhost/main"/>
(这不起作用)
I don't understand why the css file is not loaded.
I have tried using the base tag, although I'm not sure I'm using it right.
<base href="http://localhost/main" />
(this is NOT working)
推荐答案
你应该尝试使用
<link href='css/style.css' type='text/css' rel='stylesheet'/>
作为 index.php
和 css
文件夹位于同一级别.
As index.php
and the css
folder lie at the same level.
与
<link href='../css/style.css' type='text/css' rel='stylesheet'/>
,
您要求您的服务器管理 index.php
上级目录中不存在的 style.css
.
you are asking your server to look after the style.css
in upper level directory of index.php
which does not exist.
您也可以使用/
,因为它指向做网站的文档根目录.
You can also use /
because, it points do the document root of the website.
<link href="/css/style.css" type="text/css" rel="stylesheet" />
这篇关于CSS 不能从相对路径与 php 'includes' 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!