截取自emmet官网:https://docs.emmet.io/abbreviations/syntax/详情可去[官网](https://docs.emmet.io/abbreviations/syntax/)查看
Child: >
You can use
1 | div>ul>li |
…will produce
1 | <div> |
Sibling: +
Use
1 | div+p+bq |
…will output
1 | <div>div> |
Climb-up: ^
With
1 | div+div>p>span+em |
…will be expanded to
1 | <div>div> |
With
1 | div+div>p>span+em^bq |
…outputs to
1 | <div>div> |
You can use as many
1 | div+div>p>span+em^^^bq |
…will output to
1 | <div>div> |
Multiplication: *
With
1 | ul>li*5 |
…outputs to
1 | <ul> |
Grouping: ()
Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations:
1 | div>(header>ul>li*2>a)+footer>p |
…expands to
1 | <div> |
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:
1 | (div>dl>(dt+dd)*3)+footer>p |
…produces
1 | <div> |
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
ID and CLASS
In CSS, you use
1 | div#header+div.page+div#footer.class1.class2.class3 |
…will output
1 | <div id="header">div> |
Custom attributes
You can use
1 | td[title="Hello world!" colspan=3] |
…outputs
1 | <td title="Hello world!" colspan="3">td> |
- 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 ``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
1 | ul>li.item$*5 |
…outputs to
1 | <ul> |
You can use multiple
1 | ul>li.item$$$*5 |
…outputs to
1 | <ul> |
Changing numbering base and direction
With
For example, to change direction, add @-
after $
:
1 | ul>li.item$@-*5 |
…outputs to
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 mea> |
Note that ,p
etc.) but has a special meaning when written right after element. For example,a{click}
anda>{click}
will produce the same output, buta{click}+b{here}
anda>{click}+b{here}
won’t:
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:p>{Click }+a{here}+{ to continue} …produces