Naming Conventions and specifications of IDs in div + css design

Source: Internet
Author: User

As we all know, standard css naming can enhance the readability of style rules, so that you or others can modify the page later. At first, when I wrote css rules, I used Chinese abbreviations to name them. Now it seems very unprofessional, and it also wastes my energy for later maintenance.

According to my own writing habits and some online writing methods, I have summarized a set of id naming methods for myself.

Common names of CSS classes and IDs:

Website header: head/header (head) top (top)

Navigation: nanv navigation: topnav (top navigation), mainnav (main navigation), mininav (mini navigation), textnav (navigation text), and subnav (subnavigation/secondary navigation)

Banners, advertisements, and trademarks: logo, brand, and banner)

Search: sreach, sreachbox, sreachbtn, and sreachinput)

Registration and logon: login, regsiter, userbox, and password)

Layout, bigdiv, leftdiv, rightdiv, leftfloat, and rightfloat), mainbox (), subpage (subpage/second-level page)

Footer/bottom: foot/footer (footer/bottom), copyright (copyright information), sitemap (website map)

Others: content, skin, title, from, pic, news, and shop), list (list/list), newslist (News list), downloadlist (download list), piclist (Picture list), dropmenv (drop-down menu), cor/corner (rounded corner), homepage (home page), crumb (current location navigation)

In fact, I often use case and _ to distinguish the above id names. For example, the main navigation is MainNav, and if necessary, the main navigation is MainNav_1 and MainNav_2. You can also use the "type + variable name" rule for naming. For example, to write a class in red, you can use. f_red {} (f is the abbreviation of font ). The general principle is: Case, _, abbreviation, greatly enhancing the readability of the Code.

In addition, I often use the "in" method to name the sub-divd AND THE in + parent div, so that the div after the previous name does not know how to name it. Such as intop, inbox, infrom, and inlogin.

There is no really standard naming convention, and everyone has their own writing. However, we should try to rely on the specifications that everyone agrees with. After all, this has great benefits in teamwork.

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.