Emmet使用说明
Emmet使用说明
Emmet是一个使用类似css选择器的方式快速生成html代码的插件
子节点: >
你可以使用>生成子节点的内容
1 | div>ul>li |
将生成…
1 | <div> |
兄弟节点: +
你可以使用 + 生成子节点的内容
1 | div+p+bq |
将生成…
1 | <div></div> |
父级节点: ^
使用>可以生成子节点,但如果这个时候你又想在父节点中生成节点可以使用^,返回上一级节点继续生成
1 | div+div>p>span+em |
将生成…
1 | <div></div> |
1 | div+div>p>span+em^bq |
将生成…
1 | <div></div> |
多次使用^符号,作用是返回上级的上级
1 | div+div>p>span+em^^^bq |
将生成…
1 | <div></div> |
多行: *
可以使用*来生成多行相同的节点
1 | ul>li*5 |
将生成…
1 | <ul> |
分组: ()
可以使用()分组部分选择器内容,改变生成的优先级
1 | div>(header>ul>li*2>a)+footer>p |
将生成…
1 | <div> |
分组和多行结合使用的案例:
1 | (div>dl>(dt+dd)*3)+footer>p |
将生成…
1 | <div> |
ID、类
1 | div#header+div.page+div#footer.class1.class2.class3 |
将生成…
1 | <div id="header"></div> |
属性
1 | td[title="Hello world!" colspan=3] |
将生成…
1 | <td title="Hello world!" colspan="3"></td> |
数值编号
可以使用$和*来生成数值编号
1 | ul>li.item$*5 |
将生成…
1 | <ul> |
可以使用多个$$$来生成多位数值编号
1 | ul>li.item$$$*5 |
将生成…
1 | <ul> |
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 $:
1 | ul>li.item$@-*5 |
将生成…
1 | <ul> |
To change counter base value, add @N modifier to $:
1 | ul>li.item$@3*5 |
…transforms to
1 | <ul> |
You can use these modifiers together:
1 | ul>li.item$@-3*5 |
…is transformed to
1 | <ul> |
Text: {} You can use curly braces to add text to element:
1 | a{Click me} |
…will produce
1 | <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:
1 | <!-- a{click}+b{here} --> |
In second example the element is placed inside 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:
1 | p>{Click }+a{here}+{ to continue} |
…produces
1 | <p>Click <a href="">here</a> to continue</p> |
In this example, to write Click here to continue inside
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 element with here word only, without changing parent context.
For comparison, here’s the same abbreviation written without child > operator:
1 | p{Click }+a{here}+{ to continue} |
…produces
1 | <p>Click </p> |
Notes on abbreviation formatting When you get familiar with Emmet’s abbreviations syntax, you may want to use some formatting to make your abbreviations more readable. For example, use spaces between elements and operators, like this:
1 | (header > ul.nav > li*5) + footer |
But it won’t work, because space is a stop symbol where Emmet stops abbreviation parsing.
Many users mistakenly think that each abbreviation should be written in a new line, but they are wrong: you can type and expand abbreviation anywhere in the text:
参考文章原文