如何使用 Emmet 快速產生 <table> ?

栏目: CSS · 发布时间: 6年前

内容简介:VS Code 1.33.1Bootstrap 4.3.1

<table> 是 HTML 用來描述 Data 最常用的 Tag,由於還要伴隨 <thead><tbody><tr><th><td> 等 Tag,若由手工建立非常沒有效率,是否能使用 Emmet 快速產生呢 ?

Version

VS Code 1.33.1

Bootstrap 4.3.1

Table

<table class="table table-striped table-hover" border="1">
  <thead>
    <tr>
      <th>desc</th>
      <th>desc</th>
      <th>desc</th>
      <th>desc</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>data</td>
      <td>data</td>
      <td>data</td>
      <td>data</td>
    </tr>
    <tr>
      <td>data</td>
      <td>data</td>
      <td>data</td>
      <td>data</td>
    </tr>
    <tr>
      <td>data</td>
      <td>data</td>
      <td>data</td>
      <td>data</td>
    </tr>
  </tbody>
</table>

<table> 使用了 Bootstrap 的 tabletable-stripedtable-hover 三個 class,且設定 border1

另外產生一行 header,3 x 4 data。

如何使用 Emmet 快速產生 <table> ?

一段式寫法

table.table.table-striped.table-hover[border="1"]>thead>tr>th{desc}*4^^tbody>tr*3>td{data}*4

產生 table

table.table.table-striped.table-hover[border="1"]

<table> 需包含 tabletable-stripedtable-hover 3 個 class,故使用 table.table.table-striped.table-hover 連起來,由於還有 attribute border="1" ,所以再加上 [border="1"] 描述。

  • . :如同 CSS 的 class selector,描述 element 有 CSS class

  • [] :如同 CSS 的 attribute selector,描述 element 有 attribute

產生 thead

>thead>tr>th{desc}*4

<thead><tr> 只有 1 個,但都是一層一層往下,所以使用 >thead>tr

th 則有 4 個,顯示都是 desc ,所以為 th{desc}*4

  • > :如同 CSS 的 child combinator,描述 element 有 child element

  • {} :用於 binding,描述 element 的 data

產生 tbody

^^tbody>tr*3>td{data}*4

<tbody><thead> 同層,但之前已經進入 <th> ,所以要往上退兩層,使用 ^^

要產生 3 x 4 data,所以為 tr*3>td{data}*4

  • ^ :CSS 目前還沒有 parent combinator,但 ^ 很容易聯想成 parent combinator

三段式寫法

table.table.table-striped.table-hover[border="1"]>thead+tbody
tr>th{desc}*4
tr*3>td{data}*4

若覺得一段式寫法太難,也可以使用三段式寫法。

產生 table

table.table.table-striped.table-hover[border="1"]>thead+tbody

<table> 需包含 tabletable-stripedtable-hover 3 個 class,故使用 table.table.table-striped.table-hover 連起來,由於還有 attribute border="1" ,所以再加上 [border="1"] 描述。

接下來順便描述 <thead><tbody> ,由於 <thead><tbody> 在同一層,因此使用 thead+tbody

.
[]
+

產生 thead

tr>th{desc}*4

<thead> 已經產生,接下來只要產生 <tr><th> 即可。

<tr> 只有 1 個,而 <thead> 有 4 個,且 <th><tr> 之下,所以使用 tr>th{desc}*4

>
{}

產生 tbody

tr*3>td{data}*4

<tbody> 已經產生,接下來只要產生 <tr><td> 即可。

<tr> 有 3 個,而 <td> 有 4 個,且 <td><tr> 之下,所以使用 tr*3>td{data}*4

Conclusion

  • Emmet 乍看很玄,但其實 syntax 很有邏輯,又與 CSS 相似,只要心中已經有 HTML 的模樣,就能使用 Emment 描述
  • ^ 雖然不是 CSS 任何 combinator,但語意很容易聯想ˊ
  • ^^ 回退兩層算最 tricky 部分,這關能過,就很容易產生出所要的 <table>
  • 若覺得一段式寫法有難度,兩段式寫法比較容易寫出來,也不必使用 ^^ 回到上兩層,開發效率也不差

Reference

Emmet , Cheat sheet


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Algorithm Design Manual

The Algorithm Design Manual

Steve S. Skiena / Springer / 1998-8-1 / GBP 53.91

Contents u Techniques u Introduction to Algorithms u Correctness and Efficiency u Correctness u Efficiency u Expressing Algorithms u Keeping Score u The RAM Model of Computatio......一起来看看 《The Algorithm Design Manual》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具