Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the naming and writing specification of CSS

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what is the naming and writing specification of CSS", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the naming and writing standard of CSS" article.

I. document specification

1. Files are archived to the agreed directory, such as paging pagination.css 2, the file name must be composed of lowercase letters, numbers and underscores, and a single CSS file should not be too large (less than 300 lines is recommended)

II. Naming rules

In regular naming, uppercase letters are not allowed, Chinese pinyin is avoided, English words with more concise semantics should be used for combination, pay attention to abbreviations, but should not be blindly abbreviated, naming through serial numbers such as 1, 2, 3 is not allowed, the reuse of code modules should be improved as much as possible, and the style should be combined as much as possible.

2. Attribute writing order display attribute: display/list-style/position/float/clear …

Self attribute (box model): width/height/margin/padding/border text attribute: color/font/text-decoration/text-align/text-indent/vertical-align/white-space/content...

III. Standard of writing

Each declaration should end with a semicolon, whether it is the last declaration or not; all code in the CSS file should be lowercase; except for resetting the browser default style, it is forbidden to add css style settings directly to the html tag; each rule should ensure that the selector is unique and prohibit setting properties directly for classes such as global .nav / .header / .body, etc.

Fourth, code performance optimization

Selector should be as short as possible on the basis of meeting the function, reducing selector nesting and query consumption. However, you must avoid overriding the global style settings and forbid the use of the * selector in css. There is no need for units after 0. For example, 0px can be omitted to 0. 0px. 0.8px can be omitted to .8px. If possible, color should be represented by three characters as far as possible, such as # AABBCC written as # ABC. Under the premise of keeping the code decoupling, try to merge repetitive styles.

V. other norms

Do not easily change the site-wide CSS and general CSS library. After the changes, you have to go through a comprehensive test. Never use the "*" selector in CSS. For background images, please use sprite technology as much as possible to reduce http requests. Considering multi-person collaborative development, sprite can be divided by module, business and page.

The above is the content of this article on "what is the naming and writing standard of CSS". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report