0

I can't link external css file to html

The HTML file is situated in folder "header", css file header.css is also situated in this folder.

Heres the css code:

@charset "UTF-8";

h1 {
    font-size: 250%;
}

Here is the html:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="header.css" />
        <title> <?php echo $title; ?> </title>
    </head>
    <body>
        <h1> <?php echo $header; ?> </h1>
        <div id = 'myOrgButton'>
            <form method="post" action="../../controllers/MyOrganisation">
                <input type="submit" value="My Organisation" />
            </form>
        </div>
        <div id = 'logoutButton'>
            <form method="post" action="../../controllers/<?php echo $action; ?>">
                <input type="submit" value="<?php echo $action; ?>" />
            </form>
        </div>
        <hr/>

The php is here because this is header is php view that i am loading from controller. I tried defining absolute path, placing css in different folders, nothing works.

When the css is embedded in html with tag it works perfectly, so i guess the problem is with linking.

Update
I've added full html code.

9
  • are you expecting an H1 to show in the title? Commented Jan 17, 2012 at 20:35
  • Have you checked the permissions of the CSS file on the server? It's possible it cannot be read by anyone. Also, use Firebug/Web Inspector to check the console to see if you are getting a 404 on the CSS file. Commented Jan 17, 2012 at 20:37
  • When i am exploring CSS tab in fireBug, no rules are present. In HTML tab, when i try to expand link: i get 404, what that could mean? Commented Jan 17, 2012 at 20:39
  • Well, if you can host ur code somewhere, it will be easy to help you out Commented Jan 17, 2012 at 20:41
  • 404 is when the file's not found. Are you sure you're saving it to the correct folder? Commented Jan 17, 2012 at 20:41

1 Answer 1

2

Since this is a view from code igniter, the file system path to that folder is probably not the same as the URL path. First of all, you need to put it in a folder that is accessible over http. I'm not familiar with Code Igniter's implementation of this, but you should have either a "media" or "assets" folder where you put all your CSS and static images. Then, you should make the <link> href relative to the domain.

So, if your folder structure looks like this and your "assets" folder is at the root:

assets/
  images/
  css/
    header.css

Your CSS include should look like this:

<link rel="stylesheet" type="text/css" href="/assets/css/header.css" />
Sign up to request clarification or add additional context in comments.

1 Comment

you were right, only the link should have been "assets/css/header.css" Working perfectly now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.