创建比较表格

创建于 2024-12-03 / 30
字体: [默认] [大] [更大]

了解如何使用 CSS 创建比较表。


Features Basic Pro
Sample text
Sample text
Sample text
Sample text
Sample text

亲自试一试 »


如何创建比较表

步骤 1) 添加 HTML:

实例

<!-- Font Awesome Icon Library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<table>
  <tr>
    <th style="width:50%">Features</th>
    <th>Basic</th>
    <th>Pro</th>
  </tr>
  <tr>
    <td>Sample text</td>
    <td><i class="fa fa-remove"></i></td>
    <td><i class="fa fa-check"></i></td>
  </tr>
  <tr>
    <td>Sample text</td>
    <td><i class="fa fa-check"></i></td>
    <td><i class="fa fa-check"></i></td>
  </tr>
</table>
步骤 2) 添加 CSS:

实例

/* 为表格设置样式 */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  border: 1px solid #ddd;
}

/* 样式表头和表数据 */
th, td {
  text-align: center;
  padding: 16px;
}

th:first-child, td:first-child {
  text-align: left;
}

/* 斑马条纹表行 */
tr:nth-child(even) {
  background-color: #f2f2f2
}

.fa-check {
  color: green;
}

.fa-remove {
  color: red;
} 亲自试一试 »

0 人点赞过