当前位置:首页 > CSS

css制作表格模板

2026-04-02 08:25:44CSS

CSS 制作表格模板

使用 CSS 可以灵活地设计表格样式,包括边框、背景、对齐方式等。以下是一些常用的 CSS 表格模板示例。

基础表格样式

table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
}

th, td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

th {
  background-color: #f2f2f2;
  font-weight: bold;
}

tr:nth-child(even) {
  background-color: #f9f9f9;
}

tr:hover {
  background-color: #e9e9e9;
}

斑马线表格

通过 nth-child 选择器实现交替行背景色。

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

th, td {
  padding: 12px;
  border: 1px solid #ddd;
}

th {
  background-color: #4CAF50;
  color: white;
}

tr:nth-child(odd) {
  background-color: #f2f2f2;
}

响应式表格

在小屏幕设备上通过水平滚动显示表格内容。

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

th, td {
  padding: 8px;
  border: 1px solid #ddd;
}

@media screen and (max-width: 600px) {
  table {
    display: block;
    overflow-x: auto;
  }
}

圆角边框表格

为表格添加圆角边框效果。

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  padding: 10px;
  border: 1px solid #ddd;
}

th {
  background-color: #4CAF50;
  color: white;
}

悬停高亮行

鼠标悬停时高亮显示当前行。

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

th, td {
  padding: 12px;
  border: 1px solid #ddd;
}

tr:hover {
  background-color: #f5f5f5;
  transition: background-color 0.3s;
}

固定表头表格

滚动表格内容时保持表头固定。

css制作表格模板

.table-container {
  height: 300px;
  overflow-y: auto;
}

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

th {
  position: sticky;
  top: 0;
  background-color: #4CAF50;
  color: white;
}

th, td {
  padding: 10px;
  border: 1px solid #ddd;
}

使用说明

  1. 将 CSS 代码添加到 <style> 标签或外部 CSS 文件中。
  2. 确保 HTML 表格结构正确,例如:
<table>
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
    </tr>
  </tbody>
</table>
  1. 根据需要调整颜色、间距等样式属性。

标签: 表格模板
分享给朋友:

相关文章

vue实现文件模板展示

vue实现文件模板展示

Vue 实现文件模板展示的方法 在 Vue 中实现文件模板展示通常涉及文件上传、预览和模板渲染等功能。以下是几种常见的实现方式。 使用文件上传组件 通过 Vue 的文件上传组件(如 el-uploa…

css制作表格

css制作表格

CSS 制作表格的方法 使用 CSS 可以灵活地创建和样式化表格,以下是几种常见的方法: 使用 HTML 表格标签结合 CSS 样式 通过 HTML 的 <table>、<tr&g…

vue实现分组表格

vue实现分组表格

Vue 实现分组表格的方法 使用 v-for 嵌套循环实现分组 通过嵌套的 v-for 循环可以轻松实现分组表格。外层循环遍历分组数据,内层循环遍历每组中的具体项。 <template>…

vue实现上传表格

vue实现上传表格

Vue实现上传表格的方法 使用Element UI上传组件 Element UI提供了el-upload组件,可以方便地实现文件上传功能。需要安装Element UI并引入相关组件。 安装Eleme…

vue实现表格滚动

vue实现表格滚动

Vue 实现表格滚动的方法 使用 CSS 固定表头并滚动内容 通过 CSS 设置表格容器的固定高度和 overflow-y: auto,实现内容区域的滚动。表头部分使用 position: stick…

vue实现表格合并

vue实现表格合并

实现表格合并的方法 在Vue中实现表格合并通常涉及对表格数据的处理和单元格属性的动态绑定。以下是几种常见的方法: 使用rowspan和colspan属性 通过计算需要合并的行或列数,动态绑定rows…