HTMLのテーブルにアンダーラインを追加する方法

HTMLのテーブルにアンダーラインを追加する方法

テーブルにアンダーラインを追加するには、CSSを使用してテーブルのスタイルをカスタマイズする方法があります。
以下の例では、テーブルのセルにアンダーラインを追加する方法を説明します。
HTMLとCSSを別ファイルに分けて、テーブルのセルにアンダーラインを追加するスタイルを適用します。

HTMLファイル (index.html)

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>テーブルのアンダーライン</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <table class="test-table">
    <thead>
      <tr>
        <th class="test-header">ヘッダー1</th>
        <th class="test-header">ヘッダー2</th>
        <th class="test-header">ヘッダー3</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="test-cell">データ1</td>
        <td class="test-cell">データ2</td>
        <td class="test-cell">データ3</td>
      </tr>
      <tr>
        <td class="test-cell">データ4</td>
        <td class="test-cell">データ5</td>
        <td class="test-cell">データ6</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

CSSファイル (styles.css)

.test-table {
  width: 100%;
  border-collapse: collapse;
}

.test-header, .test-cell {
  border: 1px solid #ddd;
  padding: 8px;
}

.test-header {
  text-align: center;
  font-weight: bold;
  background-color: #f4f4f4;
}

.test-cell {
  text-align: left;
}

/* アンダーラインを追加 */
.test-cell {
  border-bottom: 2px solid #333;
}

.test-header {
  border-bottom: 2px solid #333;
}

この例では、テーブルのセル (test-cell クラス) およびヘッダーセル (test-header クラス) に対してアンダーラインを追加しています。
CSSで border-bottom プロパティを使用して、アンダーラインのスタイルを指定しています。
テーブル全体のスタイルは、テーブル要素 (test-table クラス) で設定しています。

アンダーラインの色やスタイルを変更したい場合は、border-bottom プロパティの値を調整できます。
例えば、border-bottom: 1px dashed #000; とすれば、点線のアンダーラインに変更できます。