简体   繁体   中英

CSS External Style Sheet isn't working, but the exact same CSS was woking on an internal Style Sheet

While making a personal website I've encountered a problem with adding a CSS Style Sheet. That Style Sheet was a local one (in the same folder has the .htm file) called "Rodrigo.css".

Here is the HTML Link tag with the CSS in the hrc:

Here is a screenshot of the CSS Style Sheet (only the beginning part):

As you can see there are not HTML Tags.

Note: The CSS that I'm using in the style sheet was previously in an internal style sheet and worked, so I don't know why it isn't working.

While making the website I used the w3schools tutorials. To do this part specifically the "CSS How to... Three ways to incert CSS".


Solved

I've found what the problem was, the HTML file was encoded in a format that wasn't supported by some browsers, and was a different format to the one of the external style sheet.

I downloaded both your HTML file and CSS file, placed them in the same folder on my desktop and the CSS file took proper effect on the HTML file. I confirmed this by removing the CSS file from the folder, observing the difference in appearance and verifying the appearance was back to normal when I copied the CSS back in.

Your code appears to be correct. Try clearing your cache, trying a different browser or open the html file in incognito mode.

Edit: Another thing you can try is replacing

<link rel="stylesheet" type="text/css" href="Rodrigo.css">

with

<link rel="stylesheet" type="text/css" href="./Rodrigo.css">

Notice the addition of ./ before your file name. This forces the browser to look in the same directory as the CSS file. I could be making this up but I think I remember having problems with either links, images or hyperlinks in older browsers when I omitted the ./

So, I've found the problem. It turned out I encoded it in UTF-8 Bom( I'm not sure that's the name of the enconding type) and that was causing problems with the browsers and the external style sheet, witch wasn't enconded in the same format. I'm going to mark this awnser had having solved my problem.

The solution is enconding the HTML source file in UTP-8, or other files that are supported and enconding the HTML and CSS source files in the same format.

Thank you for anwsering, tough.

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