开发者

What is the error in including the css by php echo statement?

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="flo开发者_运维技巧at: right; padding: 5px 15px 0pt 0pt;">Site</div>

<br>

        </div>
    </div>
    '

But the CSS is not working here.


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...


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜