我如何格式化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)

One-Line Selectors & Attributes

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)

Tabify Nested Classes

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

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

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

All Medias in One File

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)

Globals, Structure, Tags, Custom Classes, Links

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)

21 Ticks

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值