我如何格式化CSS文件

I've read about a dozen articles on CSS file formatting and management. I must say, I don't agree completely with any of them. Not to say that the way they do things is "wrong", but I don't subscribe to their way of CSS file formatting. Here's how I do it.

我已经阅读了十几篇有关CSS文件格式和管理的文章。 我必须说,我完全不同意其中的任何一个。 并不是说他们做事的方式是“错误的”,但是我不赞成他们使用CSS文件格式的方式。 这是我的方法。

一线选择器和属性 (One-Line Selectors & Attributes)

我如何格式化CSS文件

I like placing selectors and their attributes on one line. It helps me avoid endless scrolling in my CSS file. Many would argue that this makes reading the CSS difficult, but I actually find it to be easier. This also reduces the size of the CSS file.

我喜欢将选择器及其属性放在一行上。 它可以帮助我避免无休止地滚动CSS文件。 许多人会认为这使阅读CSS变得困难,但我实际上发现它更容易。 这也减小了CSS文件的大小。

制表嵌套类 (Tabify Nested Classes)

我如何格式化CSS文件

Tabifying (indenting) classes below the others is essential to CSS file readability and structure organization.

在其他类下制表(缩进)类对于CSS文件的可读性和结构组织至关重要。

一个文件中的所有媒体 (All Medias in One File)

我如何格式化CSS文件

Adding the media declarations to the CSS file allows me to place all of the CSS in one file instead of switching between buffers to update files.

将媒体声明添加到CSS文件中,使我可以将所有CSS放在一个文件中,而不用在缓冲区之间切换以更新文件。

全局变量,结构,标签,自定义类,链接 (Globals, Structure, Tags, Custom Classes, Links)

我如何格式化CSS文件

I always organize the selectors in the following orders: globals, structure, tags, custom classes, and links. This, in my opinion, outlines the importance of each group of selectors.

我总是按照以下顺序组织选择器:全局变量,结构,标签,自定义类和链接。 我认为,这概述了每组选择器的重要性。

21 cks (21 Ticks)

我如何格式化CSS文件

I try to start all braces at the 21 character mark. This number isn't necessarily meaningful -- I could indent as far out as I want.

我尝试将所有花括号都以21个字符开头。 这个数字不一定有意义-我可以缩进尽可能远的地方。

你的想法? (Your Thoughts?)

What do you think of this system? Have any suggestions?

您如何看待这个系统? 有什么建议吗?

翻译自: https://davidwalsh.name/format-css-files