介绍

Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具:

基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为“片段”。虽然片段能很好地推动你得生产力,但大多数的实现都有这样一个缺点:你必须先定义你得代码片段,并且不能再运行时进行拓展。

Emmet把片段这个概念提高到了一个新的层次:你可以设置CSS形式的能够动态被解析的表达式,然后根据你所输入的缩写来得到相应的内容。Emmet是很成熟的并且非常适用于编写HTML/XML 和 CSS 代码的前端开发人员,但也可以用于编程语言。

 

使用示例:

在编辑器中输入缩写代码:ul>li*5 ,然后按下拓展键(默认为tab),即可得到代码片段:

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

下载和安装

  1. Emmet为大部分流行的编辑器都提供了安装插件,下面是它们的下载链接:

  2. 在线编辑器的支持:

  3. 第三方插件的支持

    下面这些编辑器的插件都是由第三方开发者所提供的,所以可能并不支持所有Emmet的功能和特性。

因为我也是Sublime Text的使用者,所以下面为大家介绍一下sublime text中Emmet的安装方法:

步骤一:首先你需要为sublime text安装Package Control组件:

  1. 按Ctrl+`调出sublime text的console
  2. 粘贴以下代码到底部命令行并回车: import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installedpackagespath();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())
  3. 重启Sublime Text
  4. 在Perferences->package settings中看到package control,则表示安装成功

步骤二:使用Package Control安装Emmet插件:

  1. 按Ctrl+Shift+P命令板
  2. 输入install然后选择install Package,然后输入emmet找到 Emmet Css Snippets,点击就可以自动完成安装。

使用方法

emmet的使用方法也非常简单,以sublime text为例,直接在编辑器中输入HTML或CSS的代码的缩写,然后按tab键就可以拓展为完整的代码片段。(如果与已有的快捷键有冲突的话,可以自行在编辑器中将拓展键设为其他快捷键)

语法:

后代:>

缩写:nav>ul>li

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

兄弟:+

缩写:div+p+bq

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

上级:^

缩写:div+div>p>span+em^bq

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

缩写:div+div>p>span+em^^bq

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

分组:()

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

<div>
<header>
<ul>
<li><a href=""></a></li>
<li><a href=""></a></li>
</ul>
</header>
<footer>
<p></p>
</footer>
</div>

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

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

乘法:*

缩写:ul>li*5

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

自增符号:$

缩写:ul>li.item$*5

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

缩写:h$[title=item$]{Header $}*3

<h1 title="item1">Header 1</h1>
<h2 title="item2">Header 2</h2>
<h3 title="item3">Header 3</h3>

缩写:ul>li.item$$$*5

<ul>
<li class="item001"></li>
<li class="item002"></li>
<li class="item003"></li>
<li class="item004"></li>
<li class="item005"></li>
</ul>

缩写:ul>li.item$@-*5

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

缩写:ul>li.item$@3*5

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

ID和类属性

缩写:#header

<div id="header"></div>

缩写:.title

<div class="title"></div>

缩写:form#search.wide

<form id="search" class="wide"></form>

缩写:p.class1.class2.class3

<p class="class1 class2 class3"></p>

自定义属性

缩写:p[title="Hello world"]

<p title="Hello world"></p>

缩写:td[rowspan=2 colspan=3 title]

<td rowspan="2" colspan="3" title=""></td>

缩写:[a='value1' b="value2"]

<div a="value1" b="value2"></div>

文本:{}

缩写:a{Click me}

<a href="">Click me</a>

缩写:p>{Click }+a{here}+{ to continue}

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

隐式标签

缩写:.class

<div class="class"></div>

缩写:em>.class

<em><span class="class"></span></em>

缩写:ul>.class

<ul>
<li class="class"></li>
</ul>

缩写:table>.row>.col

<table>
<tr class="row">
<td class="col"></td>
</tr>
</table>

HTML

所有未知的缩写都会转换成标签,例如,foo → <foo></foo>

缩写:!

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body> </body>
</html>

缩写:a

<a href=""></a>

缩写:a:link

<a href="http://"></a>

缩写:a:mail

<a href="mailto:"></a>

缩写:abbr

<abbr title=""></abbr>

缩写:acronym

<acronym title=""></acronym>

缩写:base

<base href="" />

缩写:basefont

<basefont />

缩写:br

<br />

缩写:frame

<frame />

缩写:hr

<hr />

缩写:bdo

<bdo dir=""></bdo>

缩写:bdo:r

<bdo dir="rtl"></bdo>

缩写:bdo:l

<bdo dir="ltr"></bdo>

缩写:col

<col />

缩写:link

<link rel="stylesheet" href="" />

缩写:link:css

<link rel="stylesheet" href="style.css" />

缩写:link:print

<link rel="stylesheet" href="print.css" media="print" />

缩写:link:favicon

<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />

缩写:link:touch

<link rel="apple-touch-icon" href="favicon.png" />

缩写:link:rss

<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" />

缩写:link:atom

<link rel="alternate" type="application/atom+xml" title="Atom" href="atom.xml" />

缩写:meta

<meta />

缩写:meta:utf

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

缩写:meta:win

<meta http-equiv="Content-Type" content="text/html;charset=windows-1251" />

缩写:meta:vp

<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />

缩写:meta:compat

<meta http-equiv="X-UA-Compatible" content="IE=7" />

缩写:style

<style></style>

缩写:script

<script></script>

缩写:script:src

<script src=""></script>

缩写:img

<img src="" alt="" />

缩写:iframe

<iframe src="" frameborder="0"></iframe>

缩写:embed

<embed src="" type="" />

缩写:object

<object data="" type=""></object>

缩写:param

<param name="" value="" />

缩写:map

<map name=""></map>

缩写:area

<area shape="" coords="" href="" alt="" />

缩写:area:d

<area shape="default" href="" alt="" />

缩写:area:c

<area shape="circle" coords="" href="" alt="" />

缩写:area:r

<area shape="rect" coords="" href="" alt="" />

缩写:area:p

<area shape="poly" coords="" href="" alt="" />

缩写:form

<form action=""></form>

缩写:form:get

<form action="" method="get"></form>

缩写:form:post

<form action="" method="post"></form>

缩写:label

<label for=""></label>

缩写:input

<input type="text" />

缩写:inp

<input type="text" name="" id="" />

缩写:input:hidden

别名:input[type=hidden name]

<input type="hidden" name="" />

缩写:input:h

别名:input:hidden

<input type="hidden" name="" />

缩写:input:text, input:t

别名:inp

<input type="text" name="" id="" />

缩写:input:search

别名:inp[type=search]

<input type="search" name="" id="" />

缩写:input:email

别名:inp[type=email]

<input type="email" name="" id="" />

缩写:input:url

别名:inp[type=url]

<input type="url" name="" id="" />

缩写:input:password

别名:inp[type=password]

<input type="password" name="" id="" />

缩写:input:p

别名:input:password

<input type="password" name="" id="" />

缩写:input:datetime

别名:inp[type=datetime]

<input type="datetime" name="" id="" />

缩写:input:date

别名:inp[type=date]

<input type="date" name="" id="" />

缩写:input:datetime-local

别名:inp[type=datetime-local]

<input type="datetime-local" name="" id="" />

缩写:input:month

别名:inp[type=month]

<input type="month" name="" id="" />

缩写:input:week

别名:inp[type=week]

<input type="week" name="" id="" />

缩写:input:time

别名:inp[type=time]

<input type="time" name="" id="" />

缩写:input:number

别名:inp[type=number]

<input type="number" name="" id="" />

缩写:input:color

别名:inp[type=color]

<input type="color" name="" id="" />

缩写:input:checkbox

别名:inp[type=checkbox]

<input type="checkbox" name="" id="" />

缩写:input:c

别名:input:checkbox

<input type="checkbox" name="" id="" />

缩写:input:radio

别名:inp[type=radio]

<input type="radio" name="" id="" />

缩写:input:r

别名:input:radio

<input type="radio" name="" id="" />

缩写:input:range

别名:inp[type=range]

<input type="range" name="" id="" />

缩写:input:file

别名:inp[type=file]

<input type="file" name="" id="" />

缩写:input:f

别名:input:file

<input type="file" name="" id="" />

缩写:input:submit

<input type="submit" value="" />

缩写:input:s

别名:input:submit

<input type="submit" value="" />

缩写:input:image

<input type="image" src="" alt="" />

缩写:input:i

别名:input:image

<input type="image" src="" alt="" />

缩写:input:button

<input type="button" value="" />

缩写:input:b

别名:input:button

<input type="button" value="" />

缩写:isindex

<isindex />

缩写:input:reset

别名:input:button[type=reset]

<input type="reset" value="" />

缩写:select

<select name="" id=""></select>

缩写:option

<option value=""></option>

缩写:textarea

<textarea name="" id="" cols="30" rows="10"></textarea>

缩写:menu:context

别名:menu[type=context]>

<menu type="context"></menu>

缩写:menu:c

别名:menu:context

<menu type="context"></menu>

缩写:menu:toolbar

别名:menu[type=toolbar]>

<menu type="toolbar"></menu>

缩写:menu:t

别名:menu:toolbar

<menu type="toolbar"></menu>

缩写:video

<video src=""></video>

缩写:audio

<audio src=""></audio>

缩写:html:xml

<html xmlns="http://www.w3.org/1999/xhtml"></html>

缩写:keygen

<keygen />

缩写:command

<command />

缩写:bq

别名:blockquote

<blockquote></blockquote>

缩写:acr

别名:acronym

<acronym title=""></acronym>

缩写:fig

别名:figure

<figure></figure>

缩写:figc

别名:figcaption

<figcaption></figcaption>

缩写:ifr

别名:iframe

<iframe src="" frameborder="0"></iframe>

缩写:emb

别名:embed

<embed src="" type="" />

缩写:obj

别名:object

<object data="" type=""></object>

缩写:src

别名:source

<source></source>

缩写:cap

别名:caption

<caption></caption>

缩写:colg

别名:colgroup

<colgroup></colgroup>

缩写:fst, fset

别名:fieldset

<fieldset></fieldset>

缩写:btn

别名:button

<button></button>

缩写:btn:b

别名:button[type=button]

<button type="button"></button>

缩写:btn:r

别名:button[type=reset]

<button type="reset"></button>

缩写:btn:s

别名:button[type=submit]

<button type="submit"></button>

关于更多的HTML以及CSS的缩写请查看:

下载 API表直击官网文档

特别声明:文中演示代码来自于官网API:http://docs.emmet.io/cheat-sheet/

转载出处:http://www.w3cplus.com/tools/emmet-cheat-sheet.html

前端开发必备!Emmet使用手册的更多相关文章

  1. 前端开发必备 - Emmet

    介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具. 基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为"片段".虽然片 ...

  2. Web前端开发必备

    前端学习相关书籍 关于书籍 HTML.CSS 类别书籍,都是大同小异,在当当网.卓越网搜索一下很多推荐.如果感觉学的差不多了,可以关注一下<CSS禅意花园>,这个很有影响力. Javasc ...

  3. 前端开发必备之Chrome开发者工具(下篇)

    本文介绍的 Chrome 开发者工具基于 Chrome 65版本,如果你的 Chrome 开发者工具没有下文提到的那些内容,请检查下 Chrome 的版本 本文是 前端开发必备之Chrome开发者工具 ...

  4. 超高速前端开发工具——Emmet

    [由于 CSDN 不支持富文本编辑器写的文章迁移到 Markdown 编辑器中修改,已重发了一个重新排版的版本, 新版链接:http://blog.csdn.net/ys743276112/artic ...

  5. Web前端开发必备工具推荐

    http://gaohaixian.blog.163.com/blog/static/12326010520114265223489/不管你做前端开发还是网页重构,前端工具都起着非常重要的作用,这里向 ...

  6. 前端开发必备调试工具(Chrome的F12自带的功能和firebug插件差不多)

    前端开发必备调试工具(Chrome的F12自带的功能和firebug插件差不多) 一.总结 Chrome的F12自带的功能和firebug插件差不多 二.前端开发必备调试工具 在前端开发中我们经常会要 ...

  7. (webstorm的CSS插件)前端开发必备!Emmet使用手册

    介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具: 基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为“片段”.虽然片段能很好地推动你得生 ...

  8. 6.前端开发必备!Emmet使用手册

    转自:https://www.w3cplus.com/tools/emmet-cheat-sheet.html 介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个 ...

  9. 前端开发必备的Sublime 3插件

    Sublime的大名已经无需我介绍了,首先先介绍如何启用插件安装功能: 打开Sublime 3,然后按 ctrl+` 或者在View → Show Console 在打开的窗口里黏贴这个网站上的代码( ...

随机推荐

  1. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块

    系列目录 距离上次发布22讲已经有少许日子了,真是太抱歉,最近年关项目比较急,时间太紧,没有时间发布.请大家见谅 接下来我们的目标是 角色组管理 角色组权限设置 用户管理 把角色组授权给用户 给用户分 ...

  2. 如何部署Zabbix服务端

    部署环境 RHEL 6.7 Zabbix-server 2.2.14 安装zabbix官方源 # wget http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_6 ...

  3. 挑子学习笔记:BIRCH层次聚类

    转载请标明出处:http://www.cnblogs.com/tiaozistudy/p/6129425.html 本文是“挑子”在学习BIRCH算法过程中的笔记摘录,文中不乏一些个人理解,不当之处望 ...

  4. 不太被人提起的%%lockres%%的妙用

    %%lockres%% 这个值似乎很少被大家提到,甚至微软在官方文档中. 它返回是一个Hash Value,看乎这个值没什么用. 后来在实践也有它的妙用之处,比如在出现性能问题如LOCK时,一般先通过 ...

  5. “为什么DirectX里表示三维坐标要建一个4*4的矩阵?”

    0x00 前言 首先要说明的是,本文的标题事实上来自于知乎上的一个同名问题:为什么directX里表示三维坐标要建一个4*4的矩阵? - 编程 .因此,正如Milo Yip大神所说的这个标题事实上是存 ...

  6. linux内核数据结构之kfifo

    1.前言 最近项目中用到一个环形缓冲区(ring buffer),代码是由linux内核的kfifo改过来的.缓冲区在文件系统中经常用到,通过缓冲区缓解cpu读写内存和读写磁盘的速度.例如一个进程A产 ...

  7. ASP.NET Core 中文文档 第二章 指南(4.8)添加新的字段

    原文 Adding a New Field 作者 Rick Anderson 翻译 谢炀(Kiler) 校对 许登洋(Seay).高嵩(Jack) 在这个章节你将使用 Entity Framework ...

  8. Java进击C#——应用开发之Asp.net

    本章简言 上一章中笔者讲到关于Linq和EF的用法.并以hibernate来进行讲解.那么本章笔者来讲一下C#的Asp.Net.即是在B/S模式下开发.现在企业大部分的业务都是面向B/S模式的.所以对 ...

  9. Kafka资源汇总

    终于下定决心写一点普及类的东西.很多同学对Kafka的使用很感兴趣.如果你想参与到Kafka的项目开发中,很多资源是你必须要提前准备好的.本文罗列了一些常用的Kafka资源,希望对这些develope ...

  10. C# base 64图片编码解码

    使用WinForm实现了图片base64编码解码的 效果图: 示例base 64编码字符串: /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKD ...