Home >Web Front-end >HTML Tutorial >Analysis and solutions for reasons why CSS files externally referenced by HTML do not take effect

Analysis and solutions for reasons why CSS files externally referenced by HTML do not take effect

高洛峰
高洛峰Original
2017-02-21 13:39:173030browse

This article mainly introduces the analysis and solutions to the reasons why the HTML external reference css file does not take effect. This article is very detailed and has reference value. Friends who are interested can learn together. As a front-end novice, I have been tinkering with the front-end for a few days. . Today I suddenly discovered that something I believed in had a problem. . For example, I wrote a css style document under the css directory: style.css. At this time there is only one sentence in it:

body {    
background-color: #ddd;    
}

Then I introduce this external css into my html file:

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

Refresh the browser. . Wow, kao. It didn't respond, it didn't work. . I checked this path several times to make sure there was no problem, and opened chrome's F12 debugger. After making sure that the browser loaded the css file, I opened the file and saw:

HTML外部引用CSS文件不生效原因分析及解决办法


was garbled. . There should be something wrong with the encoding or the format, but I can't figure it out. . After consulting a front-end partner, I checked the current encoding of the web page:

HTML外部引用CSS文件不生效原因分析及解决办法


shows UTF-16LE encoding. .
I tried it later and used the sublime editor to modify the local css file encoding format to this utf-16LE:

HTML外部引用CSS文件不生效原因分析及解决办法


Rewritten the css code. Save and run. . Sure enough, that's it. .
But my html is specified as utf-8, and the css is utf-16, which makes me very unhappy. . So I asked again for a solution. It can be solved, and it's simple. .
Change the css to utf-8 and edit the code inside. Just declare the encoding format when introducing this css in html:

HTML外部引用CSS文件不生效原因分析及解决办法


That is, add an attribute to the link tag: charset="utf-8" Enough. . . It's really that simple. . .

For more analysis and solutions to the reasons why HTML external reference CSS files do not take effect, please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn