简体   繁体   English

Sublime-CSS-如何为整个代码中的每个部分自动添加.class?

[英]Sublime - CSS - how to auto add .class for each section in the whole code?

I wonder if there is any way to auto add class name (eg ".header") before each section in CSS code using Sublime? 我想知道是否有任何方法可以使用Sublime在CSS代码的每个部分之前自动添加类名称(例如“ .header”)?

Example: 例:

ul {
    ...;
}
a {
    ...;
}
h1 {
    ...;
}

Transform this to: 将此转换为:

.header ul {
    ...;
}
.header a {
    ...;
}
.header h1 {
    ...;
}

Kindly help :) 请帮助:)

If there are only a few instances where you want to apply this change, I'd recommend holding down ctrl & clicking on each location, this'll provide you with multiple carets that all respond to the same input, so you can type .header and all locations selected will be affected. 如果只有少数几个实例要应用此更改,建议您按住ctrl键并单击每个位置,这将为您提供多个.header ,它们均响应相同的输入,因此您可以键入.header并且所有选择的位置都会受到影响。

Or you could use find & replace with some regex to do it for you, for example 或者,您可以使用find&replace with a regex为您完成操作,例如

Find: ^([a-z0-9]{1,} \\{) 查找: ^([a-z0-9]{1,} \\{)

Replace with: .header \\1 替换为: .header \\1

This'll match any element selectors such as h1, a, p, li etc... followed by a space and {, and precede them with ".header" 这将匹配任何元素选择器,例如h1,a,p,li等...,后跟一个空格和{,并在它们前面加上“ .header”

1) ctrl + f / cmd + f 1)ctrl + f / cmd + f

2) check 'regular expression' 2)检查“正则表达式”

3) enter ^[a-z0-9]* { 3)输入^ [a-z0-9] * {

4) find all 4)找到所有

5) replace 5)更换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM