CSS writing specifications, ordering, and naming conventions

Source: Internet
Author: User
Tags print print

Reprint, Original source http://www.jb51.net/css/141575.html

Wrote so long CSS, but most of the front-end er are not in accordance with good CSS writing code to write CSS, this will affect the code reading experience, here summarizes a CSS writing specification, CSS Writing order for everyone to reference

These are references to some foreign articles and my personal experience summed up, I would like to write CSS front-end users are worth learning.

First, the CSS writing order

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

Second, the CSS writing code
1. Using CSS abbreviation properties
CSS Some properties can be abbreviated, such as Padding,margin,font, and so on, so that the refinement of the code at the same time can improve the user's reading experience.

2. Remove the "0" before the decimal point

3. Shorthand naming

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

4.16 Binary color code abbreviations

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

5 hyphen CSS Selector naming specification

1). Long name or phrase you can use the middle horizontal line to name the selector.

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

The input of the time to press a SHIFT key, browser compatibility issues (such as the use of _tips selectors named, in the IE6 is not valid) can be good to distinguish JavaScript variable naming (JS variable named "_")

6. Don't feel free to use the ID

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

7. Add a status prefix to the selector

Sometimes you can add a prefix to the selector to indicate the status, so that the semantics are clearer, such as adding the ". is-" prefix.

Third, CSS naming conventions (rules)
Common CSS Naming conventions

Head: Header
Content: Content/container
Tail: Footer
Navigation: Nav
Sidebar: Sidebar
Column: Column
Page perimeter control overall layout width: Wrapper
Middle: Left Right center
Login Strip: Loginbar
Logo: Logo
Ad: Banner
Page body: Main
Hotspot: Hot
Press: News
Download: Download
Sub-navigation: Subnav
Menus: Menu
Sub-menu: submenu
Searches: Search
Links: Friendlink
Footer: Footer
Copyrights: Copyright
Scrolling: Scroll
Contents: Content
Tags: tags
Article List: List
Hint Message: MSG
Tip: Tips
Column Title: Title
Join: Joinus
Guide: Guides
Services: Service
Registration: Regsiter
State: Status
Vote: Vote
PARTNER: Partner

notation:

/* Header */
Content Area
/* End Header */

Name of the ID:

1) Page structure

Container: Container
Page Header: Header
Content: Content/container
Page body: Main
Page End: Footer
Navigation: Nav
Sidebar: Sidebar
Column: Column
Page perimeter control overall layout width: Wrapper
Middle: Left Right center

(2) Navigation

Navigation: Nav
Main navigation: Mainnav
Sub-navigation: Subnav
Top Navigation: Topnav
Side navigation: Sidebar
Left navigation: Leftsidebar
Right navigation: Rightsidebar
Menus: Menu
Sub-menu: submenu
Caption: Title
Abstract: Summary

(3) function

Logo: Logo
Ad: Banner
Login: Login
Login Strip: Loginbar
Registration: Register
Searches: Search
Functional area: Shop
Caption: Title
Join: Joinus
State: Status
Button: BTN
Scrolling: Scroll
Tags page: tab
Article List: List
Hint Message: MSG
Present: Current
Tip: Tips
Icons: Icon
Note: note
Guide: Guild
Services: Service
Hotspot: Hot
Press: News
Download: Download
Vote: Vote
PARTNER: Partner
Links: Link
Copyrights: Copyright

Iv. Matters needing attention::

1. Lowercase;
2. Try to use English;
3. Do not add the lever and underline;
4. Try not to abbreviate unless you see the words clearly.

Five, CSS style sheet file naming

The main master.css
Module MODULE.CSS
Basic shared Base.css
Layout, Layout layout.css
Theme Themes.css
Column Columns.css
Text Font.css
Form Forms.css
Patch Mend.css
Print Print.css

CSS writing specifications, ordering, and naming conventions

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.