CSS page making tutorial: CSS writing specification and writing order

Source: Internet
Author: User
Tags add end reference variable

Article Introduction: Most of the front-end ER did not follow a good CSS writing code to write CSS, this will affect the reading experience of the code, here I summarize a CSS writing specifications, CSS writing order for everyone's reference, these are referred to some foreign articles and my personal experience summed up, I think it is worth learning for the front-end users who write CSS.

Wrote a long time CSS, but most of the front end ER did not follow the good CSS writing code to write CSS, this will affect the code reading experience, here I summarize a CSS writing order for everyone to reference, these are referred to some foreign articles and my personal experience summed up, I think it is worth learning for the front-end users who write CSS.

CSS Writing Order

Position properties (position, top, right, z-index, display, float, etc.)
Size (width, height, padding, margin)
Text series (font, Line-height, letter-spacing, color-text-align, etc.)
Background (background, border, etc.)
Other (animation, transition, etc.)

CSS Writing specification

Use CSS abbreviation properties

CSS Some attributes can be abbreviated, such as Padding,margin,font and so on, so that the streamlining of code at the same time improve the user's reading experience.

Remove the "0″" before the decimal point

Abbreviated name

Many users like shorthand class name, but the premise is to let people understand your name can be abbreviated Oh!

16 Binary color code abbreviation

Some color code can be abbreviated, we will try to abbreviate it, improve the user experience primarily.

Hyphen CSS Selector naming specification

1. Long names or phrases can be named for selectors using the middle horizontal line.

2. It is not recommended to use the "_" Underline to name the CSS selector, why?

Press one SHIFT key less when typing;
Browser compatibility issues (such as naming using _tips selectors, which are not valid in IE6)
Good at distinguishing javascript variable naming (JS variable name is with "_")

Here is a detailed discussion of dashes and underscores, English: Click to view the Chinese text: Click to view

Do not use the ID arbitrarily

ID in JS is unique, can not be used many times, and the use of class classes selector can be reused, the other ID priority and class, so the ID should be used on demand, and can not be abused.

Add a status prefix to the selector

Sometimes you can add a prefix for the state to the selector to make the semantics clearer, such as the ". is-" prefix that is added to the following image.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.