当前位置:首页 > CSS

网页表格制作css代码

2026-01-15 12:07:16CSS

基础表格样式

使用CSS为HTML表格添加基础样式,包括边框、间距和背景色:

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: #f1f1f1;
}

响应式表格设计

针对移动设备优化表格显示,当屏幕宽度不足时允许横向滚动:

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media screen and (max-width: 600px) {
  table {
    display: block;
    width: 100%;
  }
}

斑马条纹效果

为表格行添加交替颜色,提高可读性:

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

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

固定表头

当表格内容较长时,固定表头位置:

网页表格制作css代码

thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

圆角边框表格

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

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

th:first-child {
  border-top-left-radius: 5px;
}

th:last-child {
  border-top-right-radius: 5px;
}

表格单元格对齐

控制不同列的对齐方式:

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

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

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

悬停高亮效果

增强用户交互体验的悬停效果:

网页表格制作css代码

td {
  transition: background-color 0.2s ease;
}

td:hover {
  background-color: #e3f2fd;
  cursor: pointer;
}

紧凑型表格

减少表格内边距,创建更紧凑的布局:

.compact-table th, 
.compact-table td {
  padding: 4px 8px;
  font-size: 0.9em;
}

表格边框样式

自定义表格边框样式:

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

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

表格标题样式

增强表格标题的视觉效果:

caption {
  caption-side: top;
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
  text-align: center;
}

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

相关文章

vue实现表格拖动列宽

vue实现表格拖动列宽

实现表格列宽拖动的核心思路 通过监听鼠标事件(mousedown、mousemove、mouseup)实现拖动逻辑。在表头列分隔线处添加可拖拽区域,拖动时动态修改列的宽度。 基础HTML结构…

vue怎么实现文本代码实现

vue怎么实现文本代码实现

Vue 实现文本代码展示的方法 在 Vue 中展示代码块或格式化文本,可以通过多种方式实现。以下是几种常见方法: 使用 <pre> 和 <code> 标签 最简单的原生 H…

vue实现表格复选

vue实现表格复选

Vue实现表格复选的方法 基础实现 在Vue中实现表格复选功能可以通过v-model绑定复选框的状态,结合v-for循环渲染表格数据。以下是一个基础示例: <template> &l…

vue实现简单表格

vue实现简单表格

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

淘宝css代码制作

淘宝css代码制作

在淘宝店铺装修中,CSS代码用于自定义页面样式,提升视觉效果和用户体验。以下是常见的CSS代码制作方法和应用场景: 自定义店铺背景 通过CSS可以修改店铺背景颜色或图片,代码示例如下: body…

网页表格制作css代码

网页表格制作css代码

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