Home >Web Front-end >CSS Tutorial >How to standardize writing css and increase the code reading experience

How to standardize writing css and increase the code reading experience

青灯夜游
青灯夜游Original
2018-09-07 18:25:521487browse

When we are developing the front-end web page, writing css according to a good css specification can not only improve the reading experience of the code; it can also quickly find the location of the error when an error occurs, making it easy to correct. Here Design Expert Network summarizes a CSS writing specification and CSS writing order for your reference. These are summarized with reference to some foreign articles and my personal experience. I think it is worth learning for front-end users who write CSS.

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. Others ( animation, transition, etc.)

How to standardize writing css and increase the code reading experience

CSS writing specifications use CSS abbreviation properties

Some CSS properties can be abbreviated, such as padding, margin, font, etc., which streamlines the code and improves the user's reading experience.

How to standardize writing css and increase the code reading experience

Remove the "0" before the decimal point

How to standardize writing css and increase the code reading experience

Abbreviated naming

Many users like to abbreviate class names, but the premise is that people can understand your naming before you can abbreviate it!

How to standardize writing css and increase the code reading experience

Hexadecimal color code abbreviation

Some color codes can be abbreviated, let’s try to abbreviate them as much as possible to improve user experience Lord.

How to standardize writing css and increase the code reading experience

Hyphen CSS selector naming convention

1. Long names or phrases can use hyphens to name selectors .

2. It is not recommended to use "_" underscore to name CSS selectors. Why?

Press one less shift key when typing;

Browser compatibility issues (such as using the _tips selector naming is invalid in IE6)

Can be distinguished well JavaScript variable naming (JS variable naming uses "_")

How to standardize writing css and increase the code reading experience

Don't use id randomly

id is unique in JS , cannot be used multiple times, but the class selector can be used repeatedly. In addition, the priority of id is first and class, so id should be used as needed and cannot be abused.

How to standardize writing css and increase the code reading experience

Add status prefix to selector

Sometimes you can add a prefix indicating status to the selector to make the semantics clearer , for example, the following figure adds the ".is-" prefix.

How to standardize writing css and increase the code reading experience

CSS naming convention (rules) Commonly used CSS naming rules

Header (header), content (content/container) tail (footer), navigation (nav), sidebar (sidebar), column (column), page peripheral control overall layout width (wrapper), left right center (left right center), login bar (loginbar), logo (logo), advertising (banner) page main body, hot spot, news, download, subnav, menu, submenu, search, friendlink ), footer, copyright, scroll, content, tags, list of articles, msg, tips, title ), join (joinus), guide (guide), service (service), registration (regsiter), status (status), vote (vote), partner (partner)

注释的写法:
/* Header */内容区/* End Header */

id naming :

1) Page structure

Container: container, header: header, content: content/container, page body: main, footer: footer, navigation: nav, side Column: sidebar, column: column, page peripheral control overall layout width: wrapper, left right center: 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, menu: menu, submenu: submenu, title: title, summary: summary

(3) Function

标志:logo,广告:banner,登陆:login,登录条:loginbar,注册:register,搜索:search,功能区:shop,标题:title,加入:joinus,状态:status,按钮:btn,滚动:scroll,标籤页:tab,文章列表:list,提示信息:msg,当前的: current,小技巧:tips,图标: icon,注释:note,指南:guild,服务:service,热点:hot,新闻:news,下载:download,投票:vote,合作伙伴:partner,友情链接:link,版权:copyright

注意事项::
1.一律小写;
2.尽量用英文;
3.不加中槓和下划线;
4.尽量不缩写,除非一看就明白的单词。

CSS样式表文件命名

主要的(master.css) ,模块(module.css) ,基本共用 (base.css),布局、版面 (layout.css),主题( themes.css),专栏(columns.css) ,文字( font.css),表单 (forms.css),补丁( mend.css),打印 (print.css)

The above is the detailed content of How to standardize writing css and increase the code reading experience. 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

Related articles

See more