0

Hello there
I am using the following code for display the requested content.It is not the main page and here in this time only I need a css.But this CSS is not working.I dont know what is the reason.Please help me on this.

echo '
<html>
<head>      
    <title>My site</title>

<link href="css/main.css"/>
</head>
<body>
<div class="header">
        <div class="headercontent">


<div style="float: right; padding: 5px 15px 0pt 0pt;">Site</div>

<br>

        </div>
    </div>
    '

But the CSS is not working here.

2
  • why do you use echo to output this HTML code? Commented Oct 23, 2010 at 9:54
  • and your problem most likely because of wrong path. always use an absolute one. make it /css/main.css, starting from / Commented Oct 23, 2010 at 9:55

3 Answers 3

2

Your <link> needs the properties that make the browser know it's CSS, like this:

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

Unless your server is already transferring it with a "text/css" MIME type, the browser's a bit confused on what it should do with this file, unaware it's a stylesheet.

It's important to remember <link> elements have many other purposes so you need to tell it (specifically with rel) what this one does, since they can also be used for:

  • Shortcut Icons
  • iPhone/iPad Icons
  • Search specifications (e.g. opensearch)
  • Canonical links
  • etc...
Sign up to request clarification or add additional context in comments.

3 Comments

+1 Nice detailed answer. However, if you don't send a text/css content type along with the style sheet, Firefox will ignore it even if you specify a type attribute.
@Pekka - definitely good to know, the last time I tested without a correct MIME type in the headers was by accident and way back in Firefox 2 and it worked then, when did that behavior change?
I don't know when it started, I think somewhere around V2. It's still there: stackoverflow.com/questions/2883695/firefox-doesnt-show-my-css I'm not complaining though, I think it has won me three or four (promised) beers already :)
1

One thing I can see is that the link is missing the necessary rel="stylesheet". If that's not it, you will need to elaborate on what "not working" means exactly.

Comments

0

what CSS is not working? Are you getting any PHP errors? PHP and CSS are totally unrelated in this context. If your HTML is being outputted then your issue is with your CSS (likely the lack of a rel="stylesheet") not your PHP. Only PHP issue i can see is your echo is missing a closing semi-colon

Comments

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.