Emmet初体验-Emmet语法

作者: Rememberautumn 分类: Web前端 发布时间: 2016-02-19 20:18 阅读: 1,601

Emmet 语法

Emment 插件专门为谢js和css而生,使用后可以提高效率。
Emmet支持以下的编辑器

  • Sublime Text 2
  • TextMate 1.x
  • Eclipse/Aptana
  • Coda 1.6 and 2.x
  • Espresso
  • Chocolat (available via the “Install Mixin” dialog)
  • Komodo Edit/IDE (available via Tools → Add-ons)
  • Notepad++
  • PSPad
  • CodeMirror2/3
  • Bracket
    Emment插件语法,快捷键为CTRL+E

转成

Child: > You can use > operator to nest elements inside each other:

 

…will produce

 
Sibling: + Use + operator to place elements near each other, on the same level:

 

…will output

 
Climb-up: ^ With > operator you’re descending down the generated tree and positions of all sibling elements will be resolved against the most deepest element:

 

…will be expanded to

 
With ^ operator, you can climb one level up the tree and change context where following elements should appear:

 

…outputs to

 
You can use as many ^ operators as you like, each operator will move one level up:

 

…will output to

 
Multiplication: * With * operator you can define how many times element should be outputted: ul>li*5 …outputs to

 
Grouping: () Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations:

 

…expands to

 
If you’re working with browser’s DOM, you may think of groups as Document Fragments: each group contains abbreviation subtree and all the following elements are inserted at the same level as the first element of group. You can nest groups inside each
other and combine them with multiplication * operator:

 

…produces

 
With groups, you can literally write full page mark-up with a single abbreviation, but please don’t do that. Attribute operators Attribute operators are used to modify attributes of outputted elements. For example, in HTML and XML you can quickly add
class attribute to generated element. ID and CLASS In CSS, you use elem#id and elem.class notation to reach the elements with specified id or class attributes. In Emmet, you can use the very same syntax to add these attributes to specified element:

 
…will output

 

You can place as many attributes as you like inside square brackets. You don’t have to specify attribute values: td[colspan title] will produce
<td colspan=”” title=””> with tabstops inside each empty attribute (if your editor supports them). You can use single or double quotes for quoting attribute values. You don’t need to quote values if they don’t contain spaces: td[title=hello colspan=3] will work. Item numbering:
$ With multiplication * operator you can repeat elements, but with $ you can number them. Place $ operator inside element’s name, attribute’s name or attribute’s value to output current number of repeated element:

 

…outputs to

 
You can use multiple $ in a row to pad number with zeroes:

 

…outputs to

 
Changing numbering base and direction With @ modifier, you can change numbering direction (ascending or descending) and base (e.g. start value). For example, to change direction, add @- after $:

 

…outputs to

 
To change counter base value, add @N modifier to $:

 

…transforms to

 
You can use these modifiers together:

 

…is transformed to

 
Text: {} You can use curly braces to add text to element: a{Click me} …will produce

<a href=””>Click me</a> Note that {text} is used and parsed as a separate element (like, div, p etc.) but has a special meaning when written right after element. For example, a{click} and a>{click} will produce the same output, but a{click}+b{here} and
a>{click}+b{here} won’t:

<!– a{click}+b{here} –>
<a href=””>click</a><b>here</b>

<!– a>{click}+b{here} –>
<a href=””>click<b>here</b></a> In second example the <b> element is placed inside <a> element. And that’s the difference: when {text} is written right after element, it doesn’t change parent context. Here’s more complex example showing why it is important:

p>{Click }+a{here}+{ to continue}
…produces

<p>Click <a href=””>here</a> to continue</p>
In this example, to write Click here to continue inside <p> element we have explicitly move down the tree with > operator after p, but in case of a element we don’t have to, since we need <a> element with here word only, without changing parent context.

For comparison, here’s the same abbreviation written without child > operator:

p{Click }+a{here}+{ to continue}
…produces

<p>Click </p>
<a href=””>here</a> to continue

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

3条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注