预处理所有CSS选择器 [英] Prepend all CSS selectors

查看:114
本文介绍了预处理所有CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个文本过滤器或javascript / jquery函数,将在一个样式表中的所有css选择器前面加一个东西?我试图影响只有一个div与twitter引导,但它影响侧边栏外面,有没有反正呢? (我不想使用iframe。)

Is there a text filter or javascript/jquery function that will prepend all css selectors in a stylesheet with a something? I am trying to affect just one div with twitter bootstrap but it is affecting the sidebar outside of it, is there anyway to do this? (I do not want to use an iframe.)

编辑:

推荐答案

根据sabithpocker的回答,你的评论告诉我,而不是动态地更改您的样式,您正在寻找静态修改您的CSS。我认为这是最简单的正则表达式:

Your comment under sabithpocker's answer tells me that instead of dynamically changing your styles, you are looking to statically modify your CSS. I think this would be easiest with a regular expression:

查找:([,| \}] [\s $] *) ([\。#]? - ?[_ a-zA-Z] + [_ a-zA-Z0-9 - ] *)

替换为: $ 1#content $ 2

正则表达式细分


  • ([,| \}] [\s $] *) - 查找 ,或 ,新行: $ )。

  • [\。#]? - 匹配样式名称中的起始(如果存在)。

  • - ?[_ a-zA-Z] + - CSS样式名称可以以下划线或字母开头。

  • [_ a-zA-Z0-9 - ] * - 匹配剩余部分的样式名称。这可以省略,但可能很高兴知道所有修改的样式的样式名称。

  • $ 1#content $ 2 - } (或)和空格留下的方式$ 1 )。之后是您插入的文本 #content (注意空格),然后是样式名称( $ 2 )。

  • ([,|\}][\s$]*) - Finds the } or , from the previous style followed by whitespace (spaces/tabs: \s, newlines: $). The closing brace\comma keeps the regex from looking inside the body of your style.
  • [\.#]? - Matches the starting # or . in the style name, if it is present.
  • -?[_a-zA-Z]+ - CSS style names can start with an underscore or letters. Also, style names can be prepended by a dash.
  • [_a-zA-Z0-9-]* - Matches the rest of the style name. This can be omitted, but it might be nice to know the style name of all the styles that were modified.
  • $1#content $2 - The } (or ,) and whitespace is left the way it was found ($1). It is followed by your inserted text #content (note the space), which is then followed by the style name ($2).

我在Notepad ++中测试过它,它在我的样式表中工作。

应该注意,如果你的CSS没有压缩(并且是多行的),
,你将需要支持多行正则表达式的编辑器(Notepad ++)。

I tested this in Notepad++ and it works on my stylesheets.
It should be noted, that if your CSS is not compressed (and is multiline), you will need editor that supports multi-line regular expressions (Notepad++ does).

这篇关于预处理所有CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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