CSS guidelines

本文介绍了CSS和HTML的规范及最佳实践,包括缩进、换行等格式要求,多文件组织方式,目录结构的设计,以及HTML中类属性的书写建议。

原文链接:链接描述

Syntax and Formatting

At a very high-level, we want

  • two (2) space indents, no tabs;

  • 80 character wide columns;

  • multi-line CSS;

  • meaningful use of whitespace.

But, as with anything, the specifics are somewhat irrelevant—consistency is key.

Multiple Files

With the meteoric rise of preprocessors of late, more often is the case that developers are splitting CSS across multiple files.

Even if not using a preprocessor, it is a good idea to split discrete chunks of code into their own files, which are concatenated during a build step.

Table of Contents

An up-to-date table of contents provides a team with a single, canonical catalogue of what is in a CSS project, what it does, and in what order.

A simple table of contents will—in order, naturally—simply provide the name of the section and a brief summary of what it is and does.

Naturally, this section would be substantially larger on the majority of projects, but hopefully we can see how this section—in the master stylesheet—provides developers with a project-wide view of what is being used where, and why.

80 Characters Wide

Meaningful Whitespace

  • One (1) empty line between closely related rulesets.

  • Two (2) empty lines between loosely related rulesets.

  • Five (5) empty lines between entirely new sections.

HTML

When writing multiple values in a class attribute, separate them with two spaces

When multiple classes are related to each other, consider grouping them in square brackets ([ and ])

As with our rulesets, it is possible to use meaningful whitespace in your HTML. You can denote thematic breaks in content with five (5) empty lines

Separate independent but loosely related snippets of markup with a single empty line

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值