当前位置:首页 > 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表格联动

实现Vue表格联动的方法 使用Vue的响应式数据和计算属性 通过Vue的响应式数据特性,可以轻松实现表格之间的联动。定义一个共享的数据源,并在多个表格组件中使用这个数据源。利用计算属性对数据进行处理,…

vue实现动态用户表格

vue实现动态用户表格

Vue 实现动态用户表格 数据准备与响应式绑定 在 Vue 中实现动态用户表格,需先定义响应式数据。通过 data 或 ref(Composition API)存储用户数据数组,确保数据变化能触发视图…

vue表格实现单选框

vue表格实现单选框

实现单选框的基本思路 在Vue中实现表格单选框通常结合<input type="radio">或第三方组件库(如Element UI、Ant Design Vue等)。核心逻辑是通过v-m…

vue怎么实现文本代码实现

vue怎么实现文本代码实现

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

vue 实现表格单选

vue 实现表格单选

实现表格单选的方法 在Vue中实现表格单选功能可以通过多种方式完成,以下是几种常见的实现方法: 使用v-model绑定选中项 通过v-model绑定一个变量来记录当前选中的行数据。当用户点击某一行时…

css好看的表格制作

css好看的表格制作

CSS表格美化方法 边框与间距优化 使用border-collapse合并边框,避免双线边框。设置padding增加单元格内边距,提升可读性。 table { border-collapse:…