3

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

Turnip
  • 35,836
  • 15
  • 89
  • 111
  • 2
    I get a 404 error when I go to that URL, Is it possible the code is reading the 404 error page instead of a css file, which is why it keeps saying it is HTML? – TBowman Jul 14 '20 at 13:49
  • Something is misconfigured on your server. All of your CSS files throw a 404 error and many of the images throw a 508 Resource Limit Reached – Turnip Jul 14 '20 at 14:00
  • The file is not found, so instead, it loads the '404.html' page, which **is** MIME type “text/html”. So, reference typo in your ``. Have you tried `../css/style.css`? (get style from **adjacent** folder). Otherwise: show use your folder structure! – Rene van der Lende Jul 14 '20 at 15:18
  • It's not just your CSS, same happens with JS too. `The script from “https://ytmetrics.com/js/jquery.magnific-popup.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.` And in fact, when I try to access anything at all seen in your directory structure screenshot, I get `404 | page not found`. Do you have a `.htaccess` file with some broken rewrite directives in place? You've uploaded all these into your `public_html` folder, yes?! – Markus AO Jul 14 '20 at 19:13
  • Get rid of your `.htaccess` and try with a clean slate. First try to access the files directly in the browser. If that doesn't work, it won't matter how you try link them. – Markus AO Jul 14 '20 at 19:16

2 Answers2

0

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">
horrible
  • 117
  • 1
  • 8
0

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