我是一个完全的html/css初学者。
我使用PHP在不同的网页中包含相同的头部区域。在头部区域中有一个href链接,链接到外部的css文件,用于样式化多个网页的布局。
由于这些不同的网页位于根目录下的不同子文件夹中,我必须使用绝对路径来链接css文件,接下来就出现了问题:我不知道如何正确地编写链接。
当我为每个网页使用相对路径时,链接可以正常工作,但是当我尝试使用绝对路径时,却无法正常工作。
我已经尝试过以下方法:
1.href="file:///C:\xampp\htdocs\root\styles\style.css"
2.href="file:///C:/xampp/htdocs/root/styles/style.css"
3.href="file://C:/xampp/htdocs/root/styles/style.css"
4.href="C:/xampp/htdocs/root/styles/style.css"
5.href="c:/xampp/htdocs/root/styles/style.css"
以下是代码的开头部分:
<!DOCTYPE html>
<html lang="en">
<head>
<?php include('common/head.php') ?>
<title>Home</title>
</head>
这是头部区域:
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="file:///C:\xampp\htdocs\root\styles\style.css">
href="localhost/root..."
时,它会尝试连接到本地主机。当服务器(xampp的apache)在您自己的系统上运行时,这是可以的。但是,当您将此内容放到网络上时,它可能无法正常工作!使用href="/root..."
应该就可以了 :) - lupz