2011-07-27 256 views
1

我遇到了更高級導演中的樣式表問題。這是一個例子。鏈接到父樣式表 - - /?

我在example.com home文件夾中有index.php和style.css。然後,我在那裏有example.com/contact和index.php。聯繫人文件夾中的index.php指向example.com主文件夾中的樣式表。

我遇到的問題是說我想要一個div顯示爲一個塊併成爲一個超鏈接。 style.css在example.com/index.php中可以正常工作,但是如果您在/ contact文件夾中單擊該鏈接,它將嘗試訪問/contact/index.php而不僅僅是/index.php。

有沒有辦法解決這個問題?

謝謝!

回答

1

我假設你的意思是你的網站在不同目錄下的CSS路徑有問題?

您可以絕對的,或通過使用base href

<link rel="stylesheet" type="text/css" href="http://mysite.com/style.css" />

<link rel="stylesheet" type="text/css" href="/style.css" />

<base href="http://site.com/" /> 
<link rel="stylesheet" type="text/css" href="style.css" /> 
1

而不是使用鏈接樣式表(我相信上去了1個目錄)只使用/,它將進入根目錄(例如example.com/):

<link rel="stylesheet" type="text/css" href="/style.css" />