dongtuo3795
dongtuo3795
2013-03-28 17:58

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 dongleman4760 8年前

    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.

    点赞 评论 复制链接分享
  • dousuohe5882 dousuohe5882 8年前

    Use absolute URL beginning from /:

    <link rel="stylesheet" href="/webpage.css" />
    
    点赞 评论 复制链接分享