开发者

Linking to a parent stylesheet - ../?

I am having an issue with style sheets in a higher director. Here is the example;

I have index.php and style.css in the example.com home folder. Then, I have example.com/contact with index.php in there. The index.php in the contact folder, points to the stylesheet at example.com home folder.

The issue I am having is say I want a div to be displayed as a block and be a hyperlink. The style.css works fine at example.com/index.php, but if you click the link while in the /contact folder, it will try to access /contact/index.php instead of j开发者_JAVA技巧ust /index.php.

Is there a way to fix this?

Thanks!


I assume you mean you are having problems with the CSS path in different directories of your site?

You can link to the stylesheet absolutely, or by using base href ~

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

or

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

or

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


Rather than using ../ (which I believe goes up 1 directory) use just /, which will go to root directory (e.g example.com/):

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜