我常常感到困惑與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
文件夾中的鏈接不工作了。
這就是我堅持,我想,我應該使用基本標籤來解決我的問題,但我仍然對如何寫的困惑。另外,我知道我可以只改變鏈接標籤在用戶文件夾中的所有文件,但我想知道如何做這種方式(如果這甚至有可能。)