将CSS属性按任意顺序排序? [英] Sorting CSS properties into an arbitrary order?

查看:122
本文介绍了将CSS属性按任意顺序排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将所有声明/属性(不是声明块本身,而是每个块内的单个声明)按照任意顺序排序在样式表中。

I would like to programmatically sort all declarations/properties (not the declaration blocks themselves, but the individual declarations inside each block) in a style sheet into an arbitrary order.

我已经能够找到几种方法在线排序声明字母顺序,或按字母顺序,或甚至字符串长度,但这对我没有帮助,因为这些排序方法本质上是无意义的。相反,我想根据我个人认为CSS规则的方式排序,它首先放置结构声明,然后是文本声明,后面是后台声明等等。

I have been able to find several methods online for sorting declarations alphabetically, or reverse alphabetically, or even by string length, but this is unhelpful for me because those sorting methods are essentially meaningless. Instead, i would like to sort according to the way i personally think of CSS rules, which places structural declarations first, followed by text declarations, followed by background declarations, and so on.

例如,如果不清楚,假设我有一个样式表,其中包含以下内容:

As an example, in case that's not clear, suppose i have a style sheet that contains the following:

#someid {
    font-size: 200%;
    background-color: #000000;
    color: #ffffff;
    padding: 4px 8px;
}

我想能够将其排序为:

#someid {
    padding: 4px 8px;
    color: #ffffff;
    font-size: 200%;
    background-color: #000000;
}

有没有人知道一个工具可以让我创建一个模板它定义了我想要的属性的确切顺序,然后应用它来实现像上面的东西?或者,这很容易通过,例如,一个TextMate包吗?

Does anyone know of a tool that would allow me to create sort of a template that defines the exact order i want the properties to be in, and then apply it to achieve something like the above? Or would this be easy to do via, say, a TextMate bundle?

希望这不是一个可笑的问题。 :)干杯!

Hope this isn't a ridiculous question. :) Cheers!

推荐答案

你可以看看 http://www.codebeautifier.com/ 。您可以选择一堆选项...

You could maybe look into http://www.codebeautifier.com/. There are a bunch of options you could choose from...

...但这不符合您的要求。还可以选择定义自己的模板...

... but that doesn't quite fit what you're looking for. There is also the option of defining your own template...

...但是,我不知道它是如何工作的。我希望这是有帮助的。

... however, I don't quite know how it works. I hope this is helpful.

这篇关于将CSS属性按任意顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆