Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具:
基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为”片段”。虽然片段能很好地推动你得生产力,但大多数的实现都有这样一个缺点:你必须先定义你得代码片段,并且不能再运行时进行拓展。
Emmet把片段这个概念提高到了一个新的层次:你可以设置CSS形式的能够动态被解析的表达式,然后根据你所输入的缩写来得到相应的内容。Emmet是很成熟的并且非常适用于编写HTML/XML
和 CSS 代码的前端开发人员,但也可以用于编程语言。
使用示例:
在编辑器中输入缩写代码:ul>li*5 ,然后按下拓展键(默认为tab),即可得到代码片段:
1 |
<ul> |
使用方法
emmet的使用方法也非常简单,以Notepad++为例,直接在编辑器中输入HTML或CSS的代码的缩写,然后按Ctrl+E键就可以拓展为完整的代码片段。(如果与已有的快捷键有冲突的话,可以自行在编辑器中将拓展键设为其他快捷键)
语法:
后代:>
缩写:nav>ul>li
1 |
<nav> |
兄弟:+
缩写:div+p+bq
1 |
<div></div> |
上级:^
缩写:div+div>p>span+em^bq
1 |
<div></div> |
缩写:div+div>p>span+em^^bq
1 |
<div></div> |
分组:()
缩写:div>(header>ul>li*2>a)+footer>p
1 |
<div> |
缩写:(div>dl>(dt+dd)*3)+footer>p
1 |
<div> |
乘法:*
缩写:ul>li*5
1 |
<ul> |
自增符号:$
缩写:ul>li.item$*5
1 |
<ul> |
缩写:h$[title=item$]{Header $}*3
1 |
<h1 title="item1">Header 1</h1> |
缩写:ul>li.item$$$*5
1 |
<ul> |
缩写:ul>li.item$@-*5
1 |
<ul> |
缩写:ul>li.item$@3*5
1 |
<ul> |
ID和类属性
缩写:#header
1 |
<div id="header"></div> |
缩写:.title
1 |
<div class="title"></div> |
缩写:form#search.wide
1 |
<form id="search" class="wide"></form> |
缩写:p.class1.class2.class3
1 |
<p class="class1 class2 class3"></p> |
自定义属性
缩写:p[title="Hello world"]
1 |
<p title="Hello world"></p> |
缩写:td[rowspan=2 colspan=3 title]
1 |
<td rowspan="2" colspan="3" title=""></td> |
缩写:[a='value1' b="value2"]
1 |
<div a="value1" b="value2"></div> |
文本:{}
缩写:a{Click me}
1 |
<a href="">Click me</a> |
缩写:p>{Click }+a{here}+{ to continue}
1 |
<p>Click <a href="">here</a> to continue</p> |
隐式标签
缩写:.class
1 |
<div class="class"></div> |
缩写:em>.class
1 |
<em><span class="class"></span></em> |
缩写:ul>.class
1 |
<ul> |
缩写:table>.row>.col
1 |
<table> |
HTML
所有未知的缩写都会转换成标签,例如,foo → <foo></foo>
缩写:!
1 |
<!doctype html> |
缩写:a
1 |
<a href=""></a> |
缩写:a:link
1 |
<a href="http://"></a> |
缩写:a:mail
1 |
<a href="mailto:"></a> |
缩写:abbr
1 |
<abbr title=""></abbr> |
缩写:acronym
1 |
<acronym title=""></acronym> |
缩写:base
1 |
<base href="" /> |
缩写:basefont
1 |
<basefont /> |
缩写:br
1 |
<br /> |
缩写:frame
1 |
<frame /> |
缩写:hr
1 |
<hr /> |
缩写:bdo
1 |
<bdo dir=""></bdo> |
缩写:bdo:r
1 |
<bdo dir="rtl"></bdo> |
缩写:bdo:l
1 |
<bdo dir="ltr"></bdo> |
缩写:col
1 |
<col /> |
缩写:link
1 |
<link rel="stylesheet" href="" /> |
缩写:link:css
1 |
<link rel="stylesheet" href="style.css" /> |
缩写:link:print
1 |
<link rel="stylesheet" href="print.css" media="print" /> |
缩写:link:favicon
1 |
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> |
缩写:link:touch
1 |
<link rel="apple-touch-icon" href="favicon.png" /> |
缩写:link:rss
1 |
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" /> |
缩写:link:atom
1 |
<link rel="alternate" type="application/atom+xml" title="Atom" href="atom.xml" /> |
缩写:meta
1 |
<meta /> |
缩写:meta:utf
1 |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> |
缩写:meta:win
1 |
<meta http-equiv="Content-Type" content="text/html;charset=windows-1251" /> |
缩写:meta:vp
1 |
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /> |
缩写:meta:compat
1 |
<meta http-equiv="X-UA-Compatible" content="IE=7" /> |
缩写:style
1 |
<style></style> |
缩写:script
1 |
<script></script> |
缩写:script:src
1 |
<script src=""></script> |
缩写:img
1 |
<img src="" alt="" /> |
缩写:iframe
1 |
<iframe src="" frameborder="0"></iframe> |
缩写:embed
1 |
<embed src="" type="" /> |
缩写:object
1 |
<object data="" type=""></object> |
缩写:param
1 |
<param name="" value="" /> |
缩写:map
1 |
<map name=""></map> |
缩写:area
1 |
<area shape="" coords="" href="" alt="" /> |
缩写:area:d
1 |
<area shape="default" href="" alt="" /> |
缩写:area:c
1 |
<area shape="circle" coords="" href="" alt="" /> |
缩写:area:r
1 |
<area shape="rect" coords="" href="" alt="" /> |
缩写:area:p
1 |
<area shape="poly" coords="" href="" alt="" /> |
缩写:form
1 |
<form action=""></form> |
缩写:form:get
1 |
<form action="" method="get"></form> |
缩写:form:post
1 |
<form action="" method="post"></form> |
缩写:label
1 |
<label for=""></label> |
缩写:input
1 |
<input type="text" /> |
缩写:inp
1 |
<input type="text" name="" id="" /> |
缩写:input:hidden
别名:input[type=hidden name]
1 |
<input type="hidden" name="" /> |
缩写:input:h
别名:input:hidden
1 |
<input type="hidden" name="" /> |
缩写:input:text, input:t
别名:inp
1 |
<input type="text" name="" id="" /> |
缩写:input:search
别名:inp[type=search]
1 |
<input type="search" name="" id="" /> |
缩写:input:email
别名:inp[type=email]
1 |
<input type="email" name="" id="" /> |
缩写:input:url
别名:inp[type=url]
1 |
<input type="url" name="" id="" /> |
缩写:input:password
别名:inp[type=password]
1 |
<input type="password" name="" id="" /> |
缩写:input:p
别名:input:password
1 |
<input type="password" name="" id="" /> |
缩写:input:datetime
别名:inp[type=datetime]
1 |
<input type="datetime" name="" id="" /> |
缩写:input:date
别名:inp[type=date]
1 |
<input type="date" name="" id="" /> |
缩写:input:datetime-local
别名:inp[type=datetime-local]
1 |
<input type="datetime-local" name="" id="" /> |
缩写:input:month
别名:inp[type=month]
1 |
<input type="month" name="" id="" /> |
缩写:input:week
别名:inp[type=week]
1 |
<input type="week" name="" id="" /> |
缩写:input:time
别名:inp[type=time]
1 |
<input type="time" name="" id="" /> |
缩写:input:number
别名:inp[type=number]
1 |
<input type="number" name="" id="" /> |
缩写:input:color
别名:inp[type=color]
1 |
<input type="color" name="" id="" /> |
缩写:input:checkbox
别名:inp[type=checkbox]
1 |
<input type="checkbox" name="" id="" /> |
缩写:input:c
别名:input:checkbox
1 |
<input type="checkbox" name="" id="" /> |
缩写:input:radio
别名:inp[type=radio]
1 |
<input type="radio" name="" id="" /> |
缩写:input:r
别名:input:radio
1 |
<input type="radio" name="" id="" /> |
缩写:input:range
别名:inp[type=range]
1 |
<input type="range" name="" id="" /> |
缩写:input:file
别名:inp[type=file]
1 |
<input type="file" name="" id="" /> |
缩写:input:f
别名:input:file
1 |
<input type="file" name="" id="" /> |
缩写:input:submit
1 |
<input type="submit" value="" /> |
缩写:input:s
别名:input:submit
1 |
<input type="submit" value="" /> |
缩写:input:image
1 |
<input type="image" src="" alt="" /> |
缩写:input:i
别名:input:image
1 |
<input type="image" src="" alt="" /> |
缩写:input:button
1 |
<input type="button" value="" /> |
缩写:input:b
别名:input:button
1 |
<input type="button" value="" /> |
缩写:isindex
1 |
<isindex /> |
缩写:input:reset
别名:input:button[type=reset]
1 |
<input type="reset" value="" /> |
缩写:select
1 |
<select name="" id=""></select> |
缩写:option
1 |
<option value=""></option> |
缩写:textarea
1 |
<textarea name="" id="" cols="30" rows="10"></textarea> |
缩写:menu:context
别名:menu[type=context]>
1 |
<menu type="context"></menu> |
缩写:menu:c
别名:menu:context
1 |
<menu type="context"></menu> |
缩写:menu:toolbar
别名:menu[type=toolbar]>
1 |
<menu type="toolbar"></menu> |
缩写:menu:t
别名:menu:toolbar
1 |
<menu type="toolbar"></menu> |
缩写:video
1 |
<video src=""></video> |
缩写:audio
1 |
<audio src=""></audio> |
缩写:html:xml
1 |
<html xmlns="http://www.w3.org/1999/xhtml"></html> |
缩写:keygen
1 |
<keygen /> |
缩写:command
1 |
<command /> |
缩写:bq
别名:blockquote
1 |
<blockquote></blockquote> |
缩写:acr
别名:acronym
1 |
<acronym title=""></acronym> |
缩写:fig
别名:figure
1 |
<figure></figure> |
缩写:figc
别名:figcaption
1 |
<figcaption></figcaption> |
缩写:ifr
别名:iframe
1 |
<iframe src="" frameborder="0"></iframe> |
缩写:emb
别名:embed
1 |
<embed src="" type="" /> |
缩写:obj
别名:object
1 |
<object data="" type=""></object> |
缩写:src
别名:source
1 |
<source></source> |
缩写:cap
别名:caption
1 |
<caption></caption> |
缩写:colg
别名:colgroup
1 |
<colgroup></colgroup> |
缩写:fst, fset
别名:fieldset
1 |
<fieldset></fieldset> |
缩写:btn
别名:button
1 |
<button></button> |
缩写:btn:b
别名:button[type=button]
1 |
<button type="button"></button> |
缩写:btn:r
别名:button[type=reset]
1 |
<button type="reset"></button> |
缩写:btn:s
别名:button[type=submit]
1 |
<button type="submit"></button> |