导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <td> 标签


实例

一个简单的HTML表格,包含两行和四个表格单元格:

   <table>
  <tr>
    <td>Cell A</td>
    <td>Cell B</td>
  </tr>
  <tr>
    <td>Cell C</td>
    <td>Cell D</td>
  </tr>
</table>
亲自试一试 »

下面有更多实例。


定义和用法

<td> 标签定义 HTML 表格中的标准单元格。

HTML 表格有两种单元格类型:

  • 表头单元格 - 包含头部信息(由 <th> 元素创建)
  • 标准单元格 - 包含数据(由 <td> 元素创建)

<td> 元素中的文本通常是普通的左对齐文本。

<th> 元素中的文本通常呈现为粗体并且居中。


提示和注释

提示:如果需要将内容横跨多个行或列,请使用 colspan 和 rowspan 属性!


浏览器支持

元素          
<td> Yes Yes Yes Yes Yes

属性

属性 描述
colspan number 规定单元格可横跨的列数。
headers header_id 规定与单元格相关联的一个或多个表头单元格。
rowspan number 设置单元格可横跨的行数。

全局属性

<td> 标签支持 HTML 中的全局属性


事件属性

<td> 标签支持 HTML 中的事件属性


更多实例

实例

如何对齐内容<td> (使用 CSS):

   <table style="width:100%">
 <tr>
       <th>Month</th>
   <th>Savings</th>
 </tr>
     <tr>
   <td>January</td>
   <td style="text-align:right">$100</td>
 </tr>
 <tr>
       <td>February</td>
   <td style="text-align:right">$80</td>
 </tr>
</table>
亲自试一试 »

实例

如何向表格单元格添加背景色 (使用 CSS):

   <table>
 <tr>
   <th>Month</th>
       <th>Savings</th>
 </tr>
 <tr>
   <td style="background-color:#FF0000">January</td>
   <td style="background-color:#00FF00">$100</td>
 </tr>
 </table>
亲自试一试 »

实例

如何设置表格单元格的高度 (使用 CSS):

   <table>
 <tr>
   <th>Month</th>
       <th>Savings</th>
 </tr>
 <tr>
   <td style="height:100px">January</td>
   <td style="height:100px">$100</td>
 </tr>
</table>
亲自试一试 »

实例

如何在表格单元格中指定不换行 (使用 CSS):

   <table>
 <tr>
   <th>Poem</th>
 </tr>
 <tr>
   <td style="white-space:nowrap">Never increase, beyond what is necessary, the number of entities required to explain anything</td>
 </tr>
</table>
亲自试一试 »

实例

如何垂直对齐内容<td> (使用 CSS):

   <table style="width:50%;">
 <tr>
       <th>Month</th>
   <th>Savings</th>
 </tr>
 <tr style="height:100px">
   <td style="vertical-align:bottom">January</td>
   <td style="vertical-align:bottom">$100</td>
 </tr>
</table>
亲自试一试 »

实例

如何设置表格单元格的宽度 (使用 CSS):

   <table style="width:100%">
 <tr>
       <th>Month</th>
   <th>Savings</th>
 </tr>
     <tr>
   <td style="width:70%">January</td>
       <td style="width:30%">$100</td>
 </tr>
</table>
亲自试一试 »

实例

如何创建表头:

   <table>
 <tr>
   <th>Name</th>
       <th>Email</th>
   <th>Phone</th> 
 </tr>
     <tr>
   <td>John Doe</td>
       <td>john.doe@example.com</td> 
   <td>123-45-678</td>
     </tr>
</table>
亲自试一试 »

实例

如何创建带有标题的表:

   <table>
     <caption>Monthly savings</caption>
 <tr>
       <th>Month</th>
   <th>Savings</th>
 </tr>
     <tr>
   <td>January</td>
       <td>$100</td>
 </tr>
 <tr>
       <td>February</td>
   <td>$80</td>
 </tr>
   </table>
亲自试一试 »

实例

如何定义跨多行或多列的表格单元格:

   <table>
 <tr>
   <th>Name</th>
       <th>Email</th>
   <th colspan="2">Phone</th> 
     </tr>
 <tr>
   <td>John Doe</td>
       <td>john.doe@example.com</td> 
   <td>123-45-678</td>
       <td>212-00-546</td>
 </tr>
</table>
亲自试一试 »

相关页面

HTML 教程: HTML Tables

HTML DOM 参考手册: TableData 对象

CSS 教程: Styling Tables


默认CSS设置

大多数浏览器将使用以下默认值显示 <td> 元素:

td {
  display: table-cell;
  vertical-align: inherit;
} 

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。