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 */}

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.