Skip to content Skip to sidebar Skip to footer

CSS File Not Linking To HTML

I've recently started learning to code HTML and CSS by hand for the first time since the mid 90s (last time I tried to build a site, Netscape Communicator Gold 3.0 was out--so bear

Solution 1:

I inserted your code, verbatim, into a JSFiddle, and the background is red, as you wanted.

The code is not the issue, then. Instead, its a problem of the stylesheet loading properly. Try some or all of the following:

  • Check your stylesheet name, and that it is the same in the directory as it is in your HTML code; make sure stylesheet.css exists properly.
  • Double-check that the file exists in the right place, which is in the same directory as your index that you are opening.
  • Make sure the stylesheet is loading. In Chrome, if you right-click -> inspect element and go to the sources tab, you can see all loaded resources, including your CSS. If it's not loading here, it could be that it tries to load from your cache. You can force Chrome to load sites without the cache by opening the inspector again, clicking on the gear menu, and checking "Disable cache (while DevTools is open)', and reloading your site.
  • Check your local apache/webhost server to make sure that it doesn't have any settings blocking the loading of certain files or types of files. This is assuming you are running one and not just opening the file in Chrome/IE. If that is the case, you should have no problems with the file loading.
  • Make sure you saved the file. It's silly, but I can personally vouch for the time when I couldn't make my site update, and I forgot to save/update the file I was viewing.

Solution 2:

Instead of href="stylesheet.css", try href="/stylesheet.css".

I had the same issue and this worked for me.


Solution 3:

Hello, perhaps it helps to someone:

css files have to be transmitted stating "text/css" as content type (while your html page content is usually "text/html").

It is important to state the right value for transmission, because browsers check it.
I had this problem with Delphi, trying to state "DOCTYPE HTML" in a WebBroker application to use HTML5, and the problem has been solved setting it in the variable reponse.contenttype. If you use a web server, I suppose you have to put the file in the right folder for example, or set this attibute in the right place to instruct your server to send the right contenttype.

Have a nice day!

Solution 4:

Simple solution: no changes to you html code.

Procedure:

1) Log into Ubuntu as a root user
2) Go the /var/www directory and right click on the www folder, then click Properties, change the following permission as follow:

view content: anyone
change content: anyone
access content: anyone

3) Restart apache2 server type service apache2 restart
4) Finally, test the webpage

Hope this helps


Solution 5:

Just ran into same issue. It was browser cache. Ctrl-F5 helped to fix it.


Post a Comment for "CSS File Not Linking To HTML"