当前位置:首页 > CSS

网页表格制作css代码

2026-03-31 21:23:27CSS

基础表格样式

以下是一个基础的HTML表格结构,配合CSS样式使其更美观:

<table class="basic-table">
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
      <th>职业</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>28</td>
      <td>设计师</td>
    </tr>
    <tr>
      <td>李四</td>
      <td>32</td>
      <td>工程师</td>
    </tr>
  </tbody>
</table>
.basic-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-family: Arial, sans-serif;
}

.basic-table th, 
.basic-table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

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

.basic-table tr:hover {
  background-color: #f5f5f5;
}

斑马条纹表格

添加交替行颜色提高可读性:

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

响应式表格

在小屏幕上显示水平滚动条:

.responsive-table {
  overflow-x: auto;
}

圆角边框表格

为表格添加现代感的圆角:

.rounded-table {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.rounded-table th:first-child {
  border-top-left-radius: 8px;
}

.rounded-table th:last-child {
  border-top-right-radius: 8px;
}

悬停高亮效果

增强交互体验:

.highlight-table tr:hover td {
  background-color: #e6f7ff;
  color: #1890ff;
  cursor: pointer;
}

固定表头表格

长表格固定表头:

.fixed-header {
  position: relative;
  max-height: 400px;
  overflow-y: auto;
}

.fixed-header thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #f8f9fa;
}

单元格对齐方式

控制不同列的对齐方式:

.align-right {
  text-align: right;
}

.align-center {
  text-align: center;
}

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

边框样式自定义

完全控制表格边框:

.custom-border {
  border: 2px solid #333;
}

.custom-border th, 
.custom-border td {
  border: 1px solid #ccc;
}

紧凑型表格

减少内边距创建紧凑布局:

网页表格制作css代码

.compact-table th,
.compact-table td {
  padding: 6px 8px;
}

这些CSS代码片段可以根据实际需求组合使用或单独应用,通过调整颜色、间距和边框等属性,可以创建各种风格的网页表格。

标签: 表格代码
分享给朋友:

相关文章

vue实现简单表格

vue实现简单表格

Vue 实现简单表格的方法 使用原生 HTML 表格 在 Vue 模板中可以直接使用 HTML 原生表格标签,通过 v-for 动态渲染数据: <template> <tabl…

h5实现表格样式

h5实现表格样式

实现H5表格样式的方法 使用HTML和CSS创建基础表格 在HTML中,表格通过<table>标签定义,配合<tr>(行)、<td>(单元格)和<th>…

vue实现简单表格

vue实现简单表格

使用 Vue 实现简单表格 Vue 提供了多种方式实现表格功能,以下是基于 Vue 3 的两种常见方法: 基础表格实现 通过 v-for 指令循环渲染表格数据: <template&…

网页表格制作css代码

网页表格制作css代码

基础表格样式 使用CSS为HTML表格添加基础样式,包括边框、间距和背景色: table { width: 100%; border-collapse: collapse; margin…

vue实现表格树

vue实现表格树

Vue 实现表格树的方法 使用递归组件实现树形表格 在 Vue 中可以通过递归组件实现树形表格结构。定义一个组件,该组件可以调用自身来渲染子节点。 <template> &l…

vue实现表格滑动

vue实现表格滑动

Vue实现表格滑动的方法 使用CSS overflow属性实现横向滑动 在表格外层容器设置overflow-x: auto,限制表格宽度超出时出现滚动条。这种方法适合简单场景,无需额外依赖库。 &l…