当前位置:首页 > 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>

响应式表格设计

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

css制作表

@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;
  }
}

表格美化技巧

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

css制作表

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;
}

表格边框样式

自定义边框样式:

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 边框制作箭头 通过调整元素的 border 属性,利用透明边框和实色边框的组合生成箭头。例如,创建一个向右的箭头: .arrow-right { width: 0; hei…

css简历制作

css简历制作

使用CSS制作简历的基本方法 选择简洁的布局结构,单列或双列布局适合大多数简历。使用display: flex或display: grid实现响应式设计,确保在不同设备上显示良好。 字体选择上,标题…

css制作扇形图

css制作扇形图

使用CSS制作扇形图 方法一:使用clip-path和transform 通过CSS的clip-path和transform属性可以快速实现扇形效果。定义一个圆形元素,然后裁剪出扇形部分。 .fan…

css制作搜索框

css制作搜索框

制作搜索框的基本结构 使用HTML创建一个简单的搜索框结构,包含输入框和搜索按钮: <div class="search-box"> <input type="text" pl…

css右导航栏制作

css右导航栏制作

CSS右导航栏制作方法 固定定位法 使用position: fixed将导航栏固定在视窗右侧,结合right和top属性控制位置。示例代码: .right-navbar { position:…

制作css导航栏实验

制作css导航栏实验

实验目标 通过CSS实现一个水平导航栏,包含悬停效果和响应式设计。 基本HTML结构 创建一个简单的导航栏HTML结构,使用<ul>和<li>标签组织导航项:…