Emmet plug-in: HTML/CSS code quick writing artifact_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:47:10
Original
1228 people have browsed it

 

 

Emmet插件的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生。它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: 

该插件已经改名为Emmet。但Emmet不只改名,还带来了一些新特性。本文就来直观地演示给你。 


一、快速编写HTML代码 

1.  初始化 

HTML文档需要包含一些固定的标签,比如、、等,现在你只需要1秒钟就可以输入这些标签。比如输入“!”或“html:5”,然后按Tab键: 



  • html:5 或!:用于HTML5文档类型
  • html:xt:用于XHTML过渡文档类型
  • html:4s:用于HTML4严格文档类型
  • 2.  轻松添加类、id、文本和属性 

    连续输入元素名称和ID,Emmet会自动为你补全,比如输入p#foo: 



    连续输入类和id,比如p.bar#foo,会自动生成: 

    Html代码 

    1.   


    下面来看看如何定义HTML元素的内容和属性。你可以通过输入h1{foo}和a[href=#],就可以自动生成如下代码: 

    Html代码 

    1. foo

        
    2.   

     



    3.  嵌套 

    现在你只需要1行代码就可以实现标签的嵌套。 

  • >:子元素符号,表示嵌套的元素
  • +:同级标签符号
  • ^:可以使该符号前的标签提升一行
  • 效果如下图所示: 



    4.  分组 

    你可以通过嵌套和括号来快速生成一些代码块,比如输入(.foo>h1)+(.bar>h2),会自动生成如下代码: 

    Html代码 

    1.   
    2.   

        
      
  •   
  •   

      
  •   

     



    5.  隐式标签 

    声明一个带类的标签,只需输入div.item,就会生成

    。 

    在过去版本中,可以省略掉div,即输入.item即可生成
    . Now if you only enter .item, Emmet will determine based on the parent tag. For example, if you enter .item in
      ,
    • will be generated.



      The following are all implicit tag names:

    • li: for ul and ol
    • tr: used in table, tbody, thead and tfoot
    • td: used in tr
    • option: used in select and optgroup
    • 6. Define multiple elements

      To define multiple elements, you can use the * symbol. For example, ul>li*3 can generate the following code:

      Html code

        • ;/ul> The element
        • If you enter ul>li.item$*3, the following code will be generated:



      Html code



      • ;

      • //Of course, it is also possible to change it to ul>li#item$*3. The result is as follows


        1. 2. CSS abbreviation
        2. 1. Value
        For example, to define For the width of the element, just enter w100 to generate




        Css code

        width: 100px;





        In addition to px, other units can also be generated, such as inputting h10p m5e, the result is as follows:



        Css code

        height: 10%;
          margin: 5em;

        Unit alias list:


        p means %

        e means em

        x means ex

        px or no unit can be expressed as px // Added by Kerita

        2. Additional attributes
        1. Maybe you have already known some abbreviations before, such as @f , can generate:


        Css code


        @font-face {
      • font-family :;
      • src:url();
      • }
      • Some other attributes, such as background-image, border-radius, Additional options such as font, @font-face, text-outline, text-shadow, etc. can be generated through the " " symbol. For example, entering @f will generate:



        Css code

        @font-face {
        1. font-family: 'FontName';
        2. src: url('FileName.eot ');
        3. src: url('FileName.eot?#iefix') format('embedded-opentype'),
        4. url('FileName.woff') format('woff' ),
        url('FileName.ttf') format('truetype'),

        url('FileName.svg#FontName') format('svg');

        font-style: normal;

        font-weight: normal;



        3. Fuzzy matching

        If you are not sure about some abbreviations, Emmet will match the closest syntax based on your input, such as entering ov: h, ov-h, ovh and oh, the generated code is the same:

        Css code

        1. overflow :hidden; If you enter non-W3C standard CSS attributes, Emmet will automatically add the vendor prefix. For example, if you enter trs, it will generate:

        Css code



        -webkit-transform: ; -moz-transform: ;

        -ms-transform: ;

        transform: ; " symbol, you can also prefix the attribute. For example, enter -super-foo:

        Css code
        1. -webkit-super-foo: ;
        2. -moz-super-foo: ;
        3. -ms-super-foo: ;
        4. -o-super-foo: ;

        If you do not want to add all prefixes, you can use an abbreviation to specify, for example, -wm-trf means only adding -webkit and -moz prefixes:




        Css code

        -webkit-transform: ;

        -moz-transform: ;
          transform: ;
        1. The prefix abbreviation is as follows:
        2. w means -webkit-
        m means -moz -

        s means -ms -

        o means -o-

        5. Gradient

        Input lg(left, # fff 50%, #000), the following code will be generated:
        1. Css code
        background-image: - webkit-gradient(linear, 0 0, 100% 0, color-stop(0.5, #fff), to(#000));


        background-image: -webkit-linear-gradient(left, # fff 50%, #000);

        background-image: -moz-linear-gradient(left, #fff 50%, #000);

      • background-image: -o-linear -gradient(left, #fff 50%, #000);
      • background-image: linear-gradient(left, #fff 50%, #000);



      • 3. Additional functions

        Generate Lorem ipsum text

        Lorem ipsum refers to a Latin article commonly used in the field of typesetting design. The main purpose is to test the effect of the article or text in different fonts and layouts. With Emmet, you can generate these words simply by typing lorem or lipsum. You can also specify the number of characters, such as lorem10, which will generate:
        1. Quote
        2. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero delectus.

        4. Customization

        You can also customize the Emmet plug-in:

        To add a new abbreviation or update an existing abbreviation, modify the snippets.json file

        To change the behavior of Emmet filters and operations, modify the preferences.json file to define how HTML is generated Or XML code, you can modify the syntaxProfiles.json file



        5. Plug-ins for different editors

        The editors supported by Emmet are as follows (the link is for the Emmet plugin for editor):

        Sublime Text 2

        TextMate 1.x


        Eclipse/Aptana
        Coda 1.6 and 2.x
        Espresso

        Chocolat (added through the "Install Mixin" dialog box)

        Komodo Edit/IDE (added through the Tools → Add-ons menu)
      • Notepad
      • PSPad