CSS通用编码规范_html/css_WEB-ITnose
CSS通用编码规范
总结一部分前端编码规范,CSS部分先奉上,大多比较通用,应该是主流方式吧。
1 前言
本文档的目标是使 CSS 代码在团队中风格保持一致,容易被理解和被维护。
尽管本文档是针对 CSS 设计的,但是在使用各种 CSS 的预编译器(如 less、sass、stylus 等)时,适用的部分也应尽量遵循本文档的约定。
2 CSS命名方式
3 CSS基础设施
@charset "utf-8";<br /><br />
4 编码风格
空格
选择器
属性
属性前缀,标准属性放在最后,按冒号对齐方便阅读,也便于在编辑器内进行多行编辑。
.box {-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
属性书写顺序: 位置 > 盒模型 > 排版 > 外观 > 其它
Positioning 位置
// 包括 float、display、overflow……position: absolute;top: 50px;left: 0;overflow-x: hidden;
Box model 盒模型
border: 1px solid #000margin: 20px;padding: 15px;width: 240px;height: 160px;
Typographic 排版
font-size: 16px;line-height: 32px;text-align: left;word-wrap: break-word
Visual 外观
background: #fff url(images/logo.png) no-repeat;color: #000;
清除浮动
当子内容 float 浮动后,父级标签一定要清除浮动,通过对伪类设置 clear 的方式进行 clearfix。尽量不使用增加空标签的方式。[参看]
// css .clearfix::after { clear: both; content: ""; display: table; }
颜色
数值
z-index 一般以 5或10 为一个步长(如50,60,70),方便以后增加或修改
!important' 尽量不使用 !important 声明。
字体
所谓英文 Family Name,为字体文件的一个元数据,常见名称如下:
宋体 (中易宋体) | Windows | SimSun |
黑体 (中易黑体) | Windows | SimHei |
微软雅黑 | Windows | Microsoft YaHei |
微软正黑 | Windows | Microsoft JhengHei |
华文黑体 | Mac/iOS | STHeiti |
冬青黑体 | Mac/iOS | Hiragino Sans GB |
文泉驿正黑 | Linux | WenQuanYi Zen Hei |
文泉驿微米黑 | Linux | WenQuanYi Micro Hei |
//css用法h1 { font-family: "Microsoft YaHei";}
字号
字重
行高
Hack 针对某个浏览器写的样式或某个浏览器BUG的样式,必须加上注释说明
// css.clearfix{ zoom:1; /* for IE6 IE7 */}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
