Sublime Text 2之Emmet插件安装及使用

1.安装Emmet

How To Install?Reffer to this link:http://www.ituring.com.cn/article/47310

2.使用Emmet--Abbreviations Syntax

Emmet uses syntax similar to CSS selectors for describing elements’ positions inside generated tree and elements’ attributes.

Elements

You can use elements’ names like div or p to generate HTML tags. Emmet doesn’t have a predefined set of available tag names, you can write any word and transform it into a tag: div → <div></div>foo → <foo></foo> and so on.

Nesting operators

Nesting operators are used to position abbreviation elements inside generated tree: whether it should be placed inside or near the context element.

Child: >

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

div>ul>li

...will produce

<div>
    <ul> <li></li> </ul> </div>

Sibling: +

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

div+p+bq

...will output

<div></div> <p></p> <blockquote></blockquote>

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:

div+div>p>span+em 

...will be expanded to

<div></div> <div> <p><span></span><em></em></p> </div>

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

div+div>p>span+em^bq

...outputs to

<div></div> <div> <p><span></span><em></em></p> <blockquote></blockquote> </div>

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

div+div>p>span+em^^^bq

...will output to

<div></div> <div> <p><span></span><em></em></p> </div> <blockquote></blockquote>

Multiplication: *

With * operator you can define how many times element should be outputted:

ul>li*5

...outputs to

<ul>
    <li></li> <li></li> <li></li> <li></li> <li></li> </ul>

Grouping: ()

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

div>(header>ul>li*2>a)+footer>p

...expands to

<div>
    <header> <ul> <li><a href=""></a></li> <li><a href=""></a></li> </ul> </header> <footer> <p></p> </footer> </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:

(div>dl>(dt+dd)*3)+footer>p

...produces

<div>
    <dl> <dt></dt> <dd></dd> <dt></dt> <dd></dd> <dt></dt> <dd></dd> </dl> </div> <footer> <p></p> </footer>

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 classattributes. In Emmet, you can use the very same syntax to add these attributes to specified element:

div#header+div.page+div#footer.class1.class2.class3

...will output

<div id="header"></div> <div class="page"></div> <div id="footer" class="class1 class2 class3"></div>

Custom attributes

You can use [attr] notation (as in CSS) to add custom attributes to your element:

td[title="Hello world!" colspan=3]

...outputs

<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 <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:

ul>li.item$*5

...outputs to

<ul>
    <li class="item1"></li> <li class="item2"></li> <li class="item3"></li> <li class="item4"></li> <li class="item5"></li> </ul>

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

ul>li.item$$$*5

...outputs to

<ul>
    <li class="item001"></li> <li class="item002"></li> <li class="item003"></li> <li class="item004"></li> <li class="item005"></li> </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 $:

ul>li.item$@-*5

…outputs to

<ul>
    <li class="item5"></li> <li class="item4"></li> <li class="item3"></li> <li class="item2"></li> <li class="item1"></li> </ul>

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

ul>li.item$@3*5

…transforms to

<ul>
    <li class="item3"></li> <li class="item4"></li> <li class="item5"></li> <li class="item6"></li> <li class="item7"></li> </ul>

You can use these modifiers together:

ul>li.item$@-3*5

…is transformed to

<ul>
    <li class="item7"></li> <li class="item6"></li> <li class="item5"></li> <li class="item4"></li> <li class="item3"></li> </ul>

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, divp etc.) but has a special meaning when written right after element. For example, a{click} and a>{click} will produce the same output, buta{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

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:

(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:

点击观看Demo视频

This is why Emmet needs some indicators (like spaces) where it should stop parsing to not expand anything that you don’t need. If you’re still thinking that such formatting is required for complex abbreviations to make them more readable:

  • Abbreviations are not a template language, they don’t have to be “readable”, they have to be “quickly expandable and removable”.
  • You don’t really need to write complex abbreviations. Stop thinking that “typing” is the slowest process in web-development. You’ll quickly find out that constructing a single complex abbreviation is much slower and error-prone than constructing and typing a few short ones.

refference:http://docs.emmet.io/abbreviations/syntax/

转载于:https://www.cnblogs.com/cyjaysun/p/4277569.html

### 回答1: 1. 打开Sublime Text 3,点击菜单栏中的“Preferences”(偏好设置)。 2. 选择“Package Control”(包管理器),点击“Install Package”(安装插件)。 3. 在搜索框中输入“Emmet”,选择“Emmet插件进行安装。 4. 安装完成后,重启Sublime Text 3即可使用Emmet插件。 ### 回答2: Sublime Text3是编辑器中的一种,是一个功能很强大的文本编辑器。它的使用方便,而且可以安装插件,让使用更加便捷。其中,Emmet是一个非常方便的插件,它能够允许用户更快速的编写HTML和CSS代码。现在,来介绍一下如何在Sublime Text3 中安装Emmet插件。 第一步:下载Package Control 在使用前首先要先安装Sublime Text3的Package Control,它可以帮助用户快速下载和安装Sublime Text3的插件。我们可以从Sublime官网上安装,也可以在控制台中通过简单的代码完成。使用包管理器的好处就在于能够减轻用户手动安装插件带来的运行成本,提高工作效率。 第二步:安装Emmet 打开Package Control后,在搜索栏中输入Emmet,就可以找到该插件并进行安装。当插件安装成功后,我们可以在编写HTML和CSS代码时更快速的编写,提高了工作效率。 第三步:设置快捷键 在Sublime Text3中,Emmet自带了很多快捷指令,不过还有很多没有设置,如果我们想要自己设置的话可以打开菜单。Preferences -> Key Bindings,将指令添加进去,然后保存即可,就可以享受Emmet插件带来的快捷方法了。这里需要注意,不要随意修改已经设置好的快捷键,否则可能会影响工作效率。 总的来说,Sublime Text3安装Emmet插件非常简单,只需要按照上面所述步骤执行即可。使用Emmet插件可以帮助我们更快速更高效地编辑HTML和CSS代码,提高编码效率。 ### 回答3: Sublime Text3 是一款非常优秀的文本编辑器,由于其特有的插件系统,可以通过安装各种各样的插件,来扩充其功能。其中,Emmet 插件是一款非常实用的插件,能够帮助我们快速生成 HTML 和 CSS 代码。下面,我将介绍如何在 Sublime Text3 中安装 Emmet 插件。 首先,需要先打开 Sublime Text3 编辑器。然后,按下 Ctrl + Shift + P,打开命令面板。在命令面板中输入 install package,然后回车。 接着,会出现一个列表,列出了所有可用的插件包。我们需要找到 Emmet 插件包,然后选中它并点击回车。插件包开始下载,下载完成后会自动安装安装完成后,我们需要开启 Emmet 插件。方法是按下 Ctrl + Shift + P,然后输入 Emmet: Enable Emmet,按下回车即可。这时候,Emmet 插件就已经成功安装了。 使用 Emmet 插件,可以通过简单的语法,来生成 HTML 和 CSS 代码。比如,我们可以通过输入div.container>ul>li*5,然后按下 Tab 键,就能自动生成包含一个容器和一个包含五个列表项的无序列表。这大大提高了我们的编码效率。 总之,Emmet 是一个非常实用的插件,能够帮助我们快速生成 HTML 和 CSS 代码。在 Sublime Text3 中安装它也非常简单,只需要按照上述步骤操作即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值