dongtuo3795 2013-03-28 17:58
浏览 4
已采纳

CSS文件被忽略了吗?

I have a contact page on my site set up like this;

contact.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="webpage.css">
        <?php include 'header.php'; ?>
    </head>
...rest of content

I recently set up an htaccess page with some mod_rewrite changes.

So now, I have urls like

www.example.com/user

and

www.example.com/user/contact

When I look at www.example.com/user/contact the CSS is not recognized and the page does not print any of my divs but just some worded content.

So if I have

<div id="userinfo">
    User info
</div>

It just displays "User info" on the left of the page without the div being recognized.

How can I fix this problem?

  • 写回答

2条回答 默认 最新

  • dongleman4760 2013-03-28 18:03
    关注

    The href in your CSS is a relative link. So for www.example.com/user the browser will request the css file at www.example.com/webpage.css, but for www.example.com/user/contact it will request www.example.com/user/webpage.css

    That may cause part of your problem and can be fixed by preceding your hrefs with a /, so href="/webpage.css". The / will cause the browser to always request from the root of your domain so it will always request www.example.com/webpage.css regardless of the page you're on. If your css is inside some folder within your DocumentRoot (I assume you're using Apache here), you should be providing the full path to the file from the start of the doc root so possibly something like href="/css/webpage.css"

    In the comments, Michael is also correct that you may have a rewrite rule error so please add that information to your question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?