Home >Web Front-end >CSS Tutorial >Summary and sharing of precautions for writing css

Summary and sharing of precautions for writing css

黄舟
黄舟Original
2017-09-16 11:37:091491browse

CSS writing requires accumulation, and a good CSS writing habit is very beneficial to our future growth. I will update here from time to time what I usually see or encounter, and read it from time to time. A little while, but hope to make some progress.

If you readers also have opinions and suggestions, please leave a comment and I will update it, thank you!

1. CSS selectors are matched from right to left, such as #nav li. When searching, all li will be found first, and then the parent elements will be filtered to determine the matching parent element.. ....So the performance is actually very poor

So try to reduce the depth

2. Reduce the number of inline CSS

3. Use modern legal css properties

4. Avoid using descendant selectors and try to use descendant selectors

 #tp p{}   (父)                                         
 #tp>p{}  (子)

5. Avoid using wildcards. For example. mod *{}

6. Try to name as much as possible No abbreviations, unless the words are easy to understand at a glance

7. Try to use English, English abbreviations or pinyin uniformly

8, css Comments 19791207a4e0a22c816ac020ecd8cae0 Single-line comments /**/ Multi-line comments

9. Some attributes must be browser compatible

10. All lowercase, and each css item is defined as one line

11. All decorative pictures must be written in css

12. The ID must be unique and defined in the document

13. It is not recommended to use the hyphen connector in css code naming

14. Suggestions The units use relative length units, such as em and %

15. Use expression carefully in css and try not to use

16. Try to use expression in css as much as possible Do not use filters because filters will affect code reading speed and compatibility

The above is the detailed content of Summary and sharing of precautions for writing css. 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