我常常感到困惑与href属性,链接标签,以及基本标记。我不知道该如何正确链接CSS文件,以便文件可以被移动到子文件夹,并且仍然正常工作(例如以后),所以我说干就干,发现了如何在href作品指定位置时。HTML - 了解href和链接和基本标签
为了您的所知,我正在使用我的本地主机,所以我拥有主要的htdocs
文件夹,并且里面有多个文件夹,每个文件夹用于我正在处理的项目。它结束了看起来像这样:
localhost/index.php (which redirects to localhost/home/index.php)
localhost/home/
localhost/zune/
localhost/school/
localhost/aeac/
而且一般的文件夹的布局将沿着这些路线的东西:
localhost/aeac/images/
localhost/aeac/stylesheets/
localhost/aeac/scripts/
往前走,让我们说我有一个文件localhost/aeac/test/index.html
,并在其中,我有4个测试链接。我发现,
<a href="/"> will link to "localhost/"
<a href="./"> will link to "localhost/aeac/test/" (the directory the file is in.)
<a href="../"> will link to "localhost/aeac/" (the directory above the file.)
<a href="about.html">will link to "localhost/aeac/test/about.html" (the directory the file is in.)
既然我理解href的,我需要了解如何正确链接CSS。
试想一下该网站的目录是这样的:
localhost/aeac/
localhost/aeac/images/
localhost/aeac/stylesheets/
localhost/aeac/scripts/
,并就在/aeac/
文件夹我有index.html
。该文件有一个链接标签,看起来像这样:
<link rel="stylesheet" href="stylesheets/main.css" />
这样好作品出来,主要是基本的网站的结构/主题,并得到包括在每一个文件。当我必须创建子文件夹时,会出现问题。现在我们有一个localhost/aeac/users/*username*/index.html
。该网站仍然使用的main.css,但因为里边有没有stylesheets
文件夹中的链接不工作了。
这就是我坚持,我想,我应该使用基本标签来解决我的问题,但我仍然对如何写的困惑。另外,我知道我可以只改变链接标签在用户文件夹中的所有文件,但我想知道如何做这种方式(如果这甚至有可能。)