HTMLでテーブルを作成するには、いくつかの特定のタグを使用する必要があります。基本的なテーブルを作成し、さまざまなテーブルタグを理解するための段階的なガイドを次に示します。
これが基本的なHTMLテーブルの例です。
<code class="html"><table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <tr> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> </tr> </tbody> </table></code>
HTMLのネストテーブル要素の正しい構造は、テーブルが正しく表示されるようにするために不可欠です。階層と正しいネスティング順序は次のとおりです。
and :各 |
、データセルには |
を使用できます。 |
正しいネストの例: <code class="html"><table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> </tbody> </table></code> ログイン後にコピー 視覚的な外観を改善するために、HTMLテーブルをどのようにスタイリングできますか?HTMLテーブルのスタイリングは、視覚的な魅力と読みやすさを大幅に向上させることができます。 CSSを使用してこれを達成できます。ここにいくつかのテクニックがあります:
<code class="css">table, th, td { border: 1px solid black; border-collapse: collapse; }</code> ログイン後にコピー
<code class="css">th { background-color: #f2f2f2; } tr:nth-child(even) { background-color: #f9f9f9; }</code> ログイン後にコピー
<code class="css">th, td { padding: 10px; }</code> ログイン後にコピー
<code class="css">th { text-align: left; }</code> ログイン後にコピー
<code class="css">table { width: 100%; } th, td { height: 30px; }</code> ログイン後にコピー これがスタイルのテーブルの例です。 <code class="html"><style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 10px; } th { background-color: #f2f2f2; text-align: left; } tr:nth-child(even) { background-color: #f9f9f9; } </style> <table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <tr> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> </tr> </tbody> </table></code> ログイン後にコピー HTMLテーブルで
|
---|
以上がHTMLでテーブルをどのように作成しますか?さまざまなテーブルタグ(例:&lt; table&gt;&lt; tr&gt;&lt; td&gt;、&lt; th&gt;)は何ですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。