Home  >  Article  >  Web Front-end  >  What's the reason css doesn't work

What's the reason css doesn't work

青灯夜游
青灯夜游Original
2021-07-06 13:47:243438browse

Reasons why css does not work: 1. The external style sheet is not associated; 2. The encoding of the style sheet saved is wrong; 3. The selector is written incorrectly; 4. Syntax errors, including incorrectly written attribute names or attribute values , the symbols use Chinese or full-width symbols, and the html tags are not completely written; 5. The styles are cascaded.

What's the reason css doesn't work

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

When writing a page, sometimes I find that the css style I wrote does not take effect. How should we check that the css style does not take effect? What are the common reasons why css styles don’t work? Let's take a look at the reasons why css styles don't work.

Steps to troubleshoot css styles that are not working:

First, try clearing the cache, restarting the browser, etc. If it doesn't work, then conduct further troubleshooting.

Then follow the following troubleshooting process:

What's the reason css doesn't work

The following is the troubleshooting and modification method:

Remind me again to try clearing the cache before troubleshooting , restart the browser and other methods, and then conduct further troubleshooting if it fails. It's possible that you didn't do anything wrong, but it was caused by a cache or browser problem. Resetting may solve the problem.

Common reasons why css styles don’t work:

1. External style sheets are not associated

This is a very speechless mistake, but I have indeed encountered it before. After working hard to write the code, I found that none of the styles took effect. I worked stupidly for a long time, and finally found that I forgot to associate the external style. , my mood at that time was really. .

If all your styles do not take effect, first confirm whether the style sheet is associated, or whether the associated style position and name are correct

4760797a6d824998417eddf326a55d71

2. The encoding of the style sheet saved is wrong

If you suspect that the encoding of the CSS table is wrong, you can directly save the css file as a file in utf-8 encoding.

3. Wrong selection of selector If the order and name of the selectors are written incorrectly, errors may occur; the tags in

  • #html forget to write the class name and id, and the selector uses these missed class names, id, etc., the style will naturally not take effect.

  • Whether the descendant selector is written with spaces;

  • Will selectors like p.box{} be written as p. box{}, that is, an extra space is written

  • 4. Syntax error

Take the developer tools of Google Chrome as an example, generally Grammatical errors will be displayed as the style is crossed out, there will be an icon prompt on the left side of the style, and an English prompt will be displayed when the mouse is moved into it. As shown in the figure below:

General grammatical errors include:

1. The wrong attribute name is written, and the attribute value does not comply with the specification;

2. The following symbols are used Chinese or full-width symbols: What's the reason css doesn't work

,;{}:

3. The html tag is not completely written, missing "0f2b9e4ada5fafd77945e69dc6bec0d7", etc.



5. The styles are cascaded

If it is caused by cascading, you need to increase the priority of the style.

Commonly used methods include: adding elements to the selector to increase its specificity, or adding !important in the space before the style semicolon, as follows:

background-color: pink !important;
(Learning video sharing:

css video tutorial

)

The above is the detailed content of What's the reason css doesn't work. For more information, please follow other related articles on the PHP Chinese website!

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