skip to Main Content

I’m currently replacing my landing page with a new one, and I keep getting the same error when trying to link my CSS file to my HTML page. I’ve been browsing online forums for 3 full days now and nothing seems to work. I’m quite a beginner, so it could be that I’m just overlooking something really small, but it’s driving me completely nuts.

When I try to link my stylesheet, I’m getting the error "The stylesheet https://ytmetrics.com/css/style.css was not loaded because its MIME type, “text/html”, is not “text/css”."

The code I’m using to link my stylesheet looks like this:

<link href="css/style.css" rel="stylesheet">

I’ve also tried to link the CSS files like this:

<link href="/css/style.css" rel="stylesheet">

and like this:

<link href="./css/style.css" rel="stylesheet">

Unfortunately, these didn’t work as well. After trying these 3 lines (and many, many more), I thought the problem didn’t lie with linking in a wrong manner. At that point, I’ve tried to simply replace the code within the original files of the landing page and stylesheet with the new code, but it didn’t work either. I kept getting the same error. I’ve also tried to include numerous commands in the .htaccess file to make sure the CSS file would get recognized as a text/css file, but this also did not work. When I try to open the stylesheet in my browser, I simply get a 404 error.

Another thing that seems weird to me is that cPanel’s file manager says the file type is text/css, so it’s weird that I’m getting an error saying it’s a text/html file.text/css

My folders are currently set up like this:

enter image description here

The landing page is the "index.php" file, and the ‘style.css’ file is in the CSS folder.

I hope I’ve provided enough information and that someone perhaps has the solution to this problem. Let me know if you need more information!

Thanks for your time in advance!

Cheers,

Bram

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for all your answers. I really appreciate the time you took to help me.

    Unfortunately, the solutions mentioned didn't bring me any luck. Therefore, I decided to take a step back and look at it entirely differently. Eventually, I managed to tackle the problem by rewriting the link to the stylesheet in PHP instead of HTML like this:

    <?php include("application/views/site/default/css/style.php"); ?>

    This did the job and right now the stylesheet is connected to my index file. This is a bit of a quirky workaround and probably not the cleanest, but it works so it's fine, right? ;)

    Again, thanks for the time you guys took and I hope my fix could perhaps help some others.

    Cheers!

    Bram


  2. Is your css in the same directory?
    If your css is in the same directory then you could just do:

    <link href="style.css" rel="stylesheet">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search