当前位置:首页 > CSS

css 表格制作

2026-03-11 18:47:29CSS

CSS 表格制作基础

使用 CSS 可以美化 HTML 表格,使其更具视觉吸引力。以下是一个基础示例:

<table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Data 1</td>
    <td>Data 2</td>
  </tr>
</table>
table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  background-color: #f2f2f2;
}

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

响应式表格设计

对于移动设备,可以添加水平滚动:

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

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

表格悬停效果

增加交互性,当鼠标悬停时改变行背景色:

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

斑马线表格样式

交替行颜色提高可读性:

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

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

固定表头表格

长表格滚动时保持表头固定:

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

thead {
  position: sticky;
  top: 0;
  background-color: white;
  z-index: 1;
}

表格边框样式

自定义表格边框样式:

table {
  border: 2px solid #333;
}

th, td {
  border: 1px solid #aaa;
  border-style: dotted;
}

单元格对齐方式

控制单元格内容对齐:

td {
  vertical-align: middle;
  text-align: center;
}

表格标题样式

为表格添加标题并设置样式:

<caption>Monthly Sales</caption>
caption {
  caption-side: bottom;
  font-size: 0.9em;
  padding: 5px;
  color: #666;
}

合并单元格样式

处理跨行或跨列的单元格:

<td colspan="2">Merged Cell</td>
td[colspan] {
  background-color: #e1f5fe;
  text-align: center;
}

表格阴影效果

为表格添加深度感:

css 表格制作

table {
  box-shadow: 0 2px 3px rgba(0,0,0,0.1);
}

标签: 表格css
分享给朋友:

相关文章

css网页制作教程下载

css网页制作教程下载

CSS网页制作教程下载资源推荐 免费在线教程平台 W3Schools(www.w3schools.com/css/)提供交互式CSS教程,涵盖基础到高级内容,支持在线练习。 MDN Web Docs(…

css制作固定模板

css制作固定模板

使用CSS创建固定模板的方法 固定模板通常指页面布局中某些元素(如导航栏、页脚)位置固定,不随滚动条移动。以下是几种实现方式: 固定定位(Fixed Positioning) 通过position:…

css制作响应网页

css制作响应网页

响应式网页设计基础 使用CSS制作响应式网页的核心是让页面能够根据不同设备的屏幕尺寸自动调整布局和样式。主要通过媒体查询(Media Queries)、弹性布局(Flexbox)和网格布局(Grid)…

css制作卷边效果

css制作卷边效果

使用伪元素和渐变实现卷边效果 通过CSS伪元素和线性渐变可以模拟纸张卷边的视觉效果。这种方法不需要额外元素,仅通过::before或::after伪元素实现。 .element { positi…

vue实现表格多行修改

vue实现表格多行修改

实现表格多行修改的方法 数据绑定与表格渲染 使用v-model绑定表格数据到Vue实例的data属性。通过v-for循环渲染表格行,并为每行数据添加编辑状态标识。 <template>…

css字体制作

css字体制作

使用 @font-face 自定义字体 通过 @font-face 规则引入自定义字体文件(如 .woff, .woff2, .ttf)。需定义字体名称和文件路径: @font-face {…