当前位置:首页 > CSS

css制作表

2026-01-28 06:57:57CSS

使用HTML和CSS创建表格

HTML的<table>元素结合CSS可以创建结构清晰、样式美观的表格。以下是一个完整示例:

<!DOCTYPE html>
<html>
<head>
<style>
  table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-family: Arial, sans-serif;
  }

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

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

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

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

  caption {
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 10px;
  }
</style>
</head>
<body>

<table>
  <caption>员工信息表</caption>
  <tr>
    <th>姓名</th>
    <th>职位</th>
    <th>部门</th>
  </tr>
  <tr>
    <td>张三</td>
    <td>前端开发</td>
    <td>技术部</td>
  </tr>
  <tr>
    <td>李四</td>
    <td>UI设计师</td>
    <td>设计部</td>
  </tr>
</table>

</body>
</html>

响应式表格设计

对于移动设备友好的响应式表格:

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

  table caption {
    font-size: 1.3em;
  }

  table thead {
    display: none;
  }

  table tr {
    border-bottom: 2px solid #ddd;
    display: block;
    margin-bottom: 10px;
  }

  table td {
    border-bottom: 1px dotted #ccc;
    display: block;
    text-align: right;
  }

  table td:before {
    content: attr(data-label);
    float: left;
    font-weight: bold;
  }
}

表格美化技巧

添加圆角边框和阴影效果:

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

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

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

高级表格样式

斑马条纹和悬停效果增强:

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

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

tr:hover {
  transform: scale(1.01);
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

表格边框样式

自定义边框样式:

css制作表

table {
  border: 2px solid #4CAF50;
}

th, td {
  border-left: 1px dashed #ccc;
  border-right: 1px dashed #ccc;
}

tr:last-child td {
  border-bottom: none;
}

这些代码示例展示了如何创建基础表格并逐步添加样式增强效果,可根据实际需求组合使用或调整具体参数。

标签: css
分享给朋友:

相关文章

制作css

制作css

CSS基础语法 CSS规则由选择器和声明块组成。选择器指向需要设置样式的HTML元素,声明块包含一个或多个用分号分隔的声明。每个声明由属性和值组成,用冒号分隔。 选择器 { 属性: 值; 属…

css 制作按钮

css 制作按钮

基础按钮样式 使用CSS创建一个基础按钮需要定义padding、background-color、border和border-radius等属性。以下是一个简单示例: .button { pad…

css按钮制作

css按钮制作

基础按钮样式 使用CSS创建基础按钮需要定义padding、background-color、border和border-radius等属性。以下是一个简单的按钮样式示例: .button {…

css制作下拉菜单

css制作下拉菜单

CSS 制作下拉菜单的方法 使用纯 CSS 可以创建简单的下拉菜单效果,主要依赖 :hover 伪类和 display 属性控制子菜单的显示与隐藏。 基础 HTML 结构 <div class…

dw制作css

dw制作css

使用DW(Dreamweaver)制作CSS的步骤 在Adobe Dreamweaver中创建和编辑CSS文件可以通过可视化界面或直接编写代码完成。以下是具体操作方法: 新建CSS文件 打开Drea…

如何制作css

如何制作css

创建CSS文件 新建一个纯文本文件,将文件扩展名改为.css,例如style.css。确保文件名不含空格或特殊字符,使用连字符或下划线分隔单词。 编写CSS语法 CSS规则由选择器和声明块组成。选择…