search
HomeWeb Front-endHTML TutorialEmmet plug-in: HTML/CSS code quick writing artifact_html/css_WEB-ITnose

 

 

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
    1. ;/ul> The element
    2. If you enter ul>li.item$*3, the following code will be generated:



    Html code


    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
  • Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

    The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

    What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

    The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

    What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

    The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

    What is the purpose of the <iframe> tag? What are the security considerations when using it?What is the purpose of the <iframe> tag? What are the security considerations when using it?Mar 20, 2025 pm 06:05 PM

    The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

    What is the viewport meta tag? Why is it important for responsive design?What is the viewport meta tag? Why is it important for responsive design?Mar 20, 2025 pm 05:56 PM

    The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

    How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

    The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

    What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

    Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

    How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

    This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    EditPlus Chinese cracked version

    EditPlus Chinese cracked version

    Small size, syntax highlighting, does not support code prompt function

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version