如何在HTML中创建表格的行和列?

要在HTML中创建表的行和列,请使用<table>标记。一个表由行和列组成,可以使用一个或多个<tr>,<th>和<td>元素进行设置。表行由<tr>标记定义。对于表的行和列,分别使用<tr>标记和<td>标记。<td>标签

请记住,HTML5不支持许多表格属性,例如align,bgcolor,border,cellpadding,cellspacing。不要使用它们。使用style属性添加CSS属性,以向表添加边框。我们还使用<style>标记来设置表格边框的样式。

示例

您可以尝试运行以下代码在HTML中创建表行和列。

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>

   <body>
      <h2>Understanding Tables</h2>
      <table>
         <tr>
            <th>Header: This is row1 column1</th>
            <th>Header: This is row1 column2</th>
         </tr>
         <tr>
            <td>This is row2 column1</td>
            <td>This is row2 column2</td>
         </tr>
      </table>
   </body>
</html>