简体   繁体   中英

My css works on my local xampp server and not on my website

I have a website . My css is not being applied to it. These files are exactly the same as the ones I have locally. These work on my own localhost. I use php in my css document so the file extension is .php

(my css document) main.php:

<?php
    header("Content-type: text/css; charset: utf-8");
?>

my index document calling in main.php:

<head>
    <meta charset="utf-8">
    <title>Chris Munroe</title>
    <link rel = "stylesheet" href = "css/normalize.css">
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
    <link rel = "stylesheet" href = "css/main.php">

</head>

If you click to my about page there is another css document specifically for that page. On the website, you will see, that it works fine. What is wrong here? Can you not mingle php with css? Does it matter where I use that header in my php/css document?

Wow. It was because the utf was lower case. That was it.

fix:

header("Content-type: text/css; charset: UTF-8");

You can check the website for yourself its all good now....

As Dagon pointed even though you are setting the content type you need to do this to enforce it.
Place the CSS in a separate folder and then

Create a *.htaccess file in that folder and add the following:

AddHandler application/x-httpd-php .css

This should do the trick for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM