据我了解,<base href="">
可以用于指向您的“根”文件夹,以便使用绝对路径访问根文件夹中包含的链接。
我的文件位于本地主机上。每个项目的主要文件结构如下:
在我的CSS文件中,我无法使用绝对路径。例如:要获取背景图片,我必须使用"../../images/imagename.png"
在css文件中,如果我尝试使用/images/imagename.png
,则该链接无效。
在css文件中,如果我尝试使用C:/full_path_to_localhost/root/images/imagename.png
此工作
在 root / includes / header.php (头文件,直接存储在“ includes”文件夹中。不在子文件夹中)中,我在“标题,在每个样式表上方:
<title></title>
<base href="C:/full_path_to_localhost/root/">
<link rel="">
注意,我也尝试过使用file:///C:/full_path_to_localhost/root/
在css文件中,我尝试执行/images/imagename.png
和images/imagename.png
,但仍然看不到图像。
如果我将完整路径:“ C:/full_path_to_localhost/root/images/imagename.png”复制/粘贴到文件资源管理器中,则会显示我的图像
我不确定我在做什么错或我忽略了什么