Home > Web Front-end > Front-end Q&A > What's the reason css doesn't work

What's the reason css doesn't work

青灯夜游
Release: 2021-07-06 13:47:24
Original
3509 people have browsed it

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

<link rel="stylesheet" href="css/index.css"/>
Copy after login

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

,;{}:
Copy after login

3. The html tag is not completely written, missing "<" or ">", 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;
Copy after login

(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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template