Why is my CSS not appearing?
html - Complete list of reasons why a css file might not be working - Stack Overflow
CSS not being applied in pages :/
My CSS is not being applied to my html, how do i fix it? - Stack Overflow
Videos
Hello! I'm absolutely brand new to this (I learned very basic HTML as a child but not much), so I've been following this tutorial to try and make a basic layout for my site. I've been writing the code in CodePen and everything seems to look fine (don't mind the silly placeholder text): https://codepen.io/catciuin/pen/OJvNzeM
I've already added the basic HTML to Neocities, which is also working fine. However, when I try to add the CSS link using <link rel="stylesheet" href="style.css">, it just doesn't show up at all. The stylesheet is just saved as "style.css" and is in the same folder as index.html - just the default folder, I haven't added any new ones. I've googled around and tried a few solutions with no luck, including adding other tags, creating a new .css file, adding . or ./ in front of style.css.
It also doesn't show up even if I add it into the HTML, without a separate file. I've tried adding it at the top or bottom of the page, inside <head> tags, just about every suggestion I've been able to find.
I can't figure out if I'm missing something really obvious or what :( any help would be really appreciated!
EDIT: I ran the same HTML & CSS on w3spaces and it seems to be just fine. Is this a neocities specific issue? :s
Are you sure the stylesheet is loaded? You can see it using the "Net" tab of Firebug on firefox, or on "Network" tab of the Console of your browser.
(If 1 works) can you have a simple sample style and see whether this is getting applied (and visible in the console)?
Firefox can reject a stylesheet if it is not served with a content type of "text/css". (This is separate from the 'type="text/css"' declaration in the HTML.)
I had a similar issue, I believe the problem was coming from the name of my CSS folder in which I had the CSS file. The folder was named "CSS", I'm not sure why it was causing issues but when I put my css file into my "js" folder it worked perfectly fine. Then I created a new folder named "myCSS" and it worked still. This is a weird workaround but it solved my issue and it may be useful to someone else.
also for the link I just had <link rel="stylesheet" href="myCSS/style.css" />
Can you check your network tab that your style.css is fetched from server and there is no 404 not found.
I would say try "/styles.css"
LPChip suggested me to use the debugger/inspector of Firefox and there, the head is greyed out. On further investigation, I noticed it said "css was not loaded because its mime type "text/html" is not "text/css"
That made me check something...
I got the solution:
I had an apache mod_rewrite activated. While the path was correct, it seems that this mod_rewrite or the dedicated php for the redirection somehow told the browser that the file was html not css.
I had a similar issue. Was setting up a NGINX from scratch and all the styles for my project were not applied. But they existed and I did not had any other error.
I found out that I had to apply the correct mime types to all files served by NGINX. Before the fix it was text/plain and this did not worked.
I fixed it by adding those lines to NGINX configuration:
http {
# other config before ...
include /etc/nginx/mime.types;
default_type application/octet-stream;
# rest of config ...
}
Are you able to see the CSS file loaded in the Network tab of your browser?
How to:
Developer Console > Network
In order for the above to work, open the developer console for your browser (here is a good link to find out for your browser: Check Opening Browser Developer Console)
If the CSS file is showing up in the Network tab, it means your CSS selectors are not correct.
If the CSS file isn't showing up, your path isn't correct. As a test put the entire url (absolute) in the src', like this:
<link rel="stylesheet" href="https://mywebsite.com/css/main.css">
I encountered a similar issue, and upon reviewing my code, I discovered the culprit.
<link rel="stylesheet" type="text/css" href="/styles.css">
The / in the href="" attribute wasn't necessary since both the HTML file and the CSS file were located in the same folder. Despite the live server rendering the CSS changes, it doesn't guarantee that the path is correctly specified and recognized by the browser. This oversight might also affect other files, such as images. Hence, it's crucial to ensure the accuracy of file paths to prevent such issues.