当前位置:首页 > CSS

css表格表单制作

2026-01-27 21:02:35CSS

CSS表格制作

使用CSS可以快速美化HTML表格,提升视觉效果和用户体验。以下是一个基础表格样式示例:

<table class="styled-table">
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
      <th>职业</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>28</td>
      <td>设计师</td>
    </tr>
    <tr>
      <td>李四</td>
      <td>32</td>
      <td>工程师</td>
    </tr>
  </tbody>
</table>
.styled-table {
  width: 100%;
  border-collapse: collapse;
  margin: 25px 0;
  font-size: 0.9em;
  font-family: sans-serif;
  min-width: 400px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}

.styled-table thead tr {
  background-color: #009879;
  color: #ffffff;
  text-align: left;
}

.styled-table th,
.styled-table td {
  padding: 12px 15px;
}

.styled-table tbody tr {
  border-bottom: 1px solid #dddddd;
}

.styled-table tbody tr:nth-of-type(even) {
  background-color: #f3f3f3;
}

.styled-table tbody tr:last-of-type {
  border-bottom: 2px solid #009879;
}

.styled-table tbody tr:hover {
  background-color: #f1f1f1;
}

CSS表单制作

表单是网页交互的重要组件,CSS可以显著提升表单的可用性和美观度:

<form class="styled-form">
  <div class="form-group">
    <label for="name">姓名</label>
    <input type="text" id="name" placeholder="请输入姓名">
  </div>
  <div class="form-group">
    <label for="email">邮箱</label>
    <input type="email" id="email" placeholder="请输入邮箱">
  </div>
  <div class="form-group">
    <label for="message">留言</label>
    <textarea id="message" placeholder="请输入留言"></textarea>
  </div>
  <button type="submit">提交</button>
</form>
.styled-form {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
  background: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.form-group {
  margin-bottom: 20px;
}

.styled-form label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: #333;
}

.styled-form input[type="text"],
.styled-form input[type="email"],
.styled-form textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.styled-form textarea {
  height: 100px;
  resize: vertical;
}

.styled-form button {
  background-color: #009879;
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
}

.styled-form button:hover {
  background-color: #007f63;
}

响应式表格处理

针对移动设备优化表格显示:

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

  .styled-table thead {
    display: none;
  }

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

  .styled-table td {
    display: block;
    text-align: right;
    padding-left: 50%;
    position: relative;
  }

  .styled-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    width: 50%;
    padding-left: 15px;
    font-weight: bold;
    text-align: left;
  }
}

表单验证样式

为表单添加验证反馈样式:

css表格表单制作

.styled-form input:invalid {
  border-color: #ff4444;
}

.styled-form input:valid {
  border-color: #00C851;
}

.styled-form .error-message {
  color: #ff4444;
  font-size: 14px;
  margin-top: 5px;
  display: none;
}

.styled-form input:invalid + .error-message {
  display: block;
}

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

相关文章

在vue实现学生表格

在vue实现学生表格

实现学生表格的基本结构 在Vue中实现学生表格需要使用<table>标签结合Vue的数据绑定功能。准备一个数组存储学生数据,通过v-for指令动态渲染表格行。 <template&…

uniapp 表格导入

uniapp 表格导入

uniapp 表格导入的实现方法 使用 uni.chooseFile 选择文件 在 uniapp 中,可以通过 uni.chooseFile API 让用户选择本地文件。该 API 支持多平台,包括…

vue快速实现表单

vue快速实现表单

Vue 快速实现表单的方法 使用 Vue 快速实现表单可以通过多种方式完成,以下是几种常见的方法: 使用 v-model 双向绑定 Vue 提供了 v-model 指令,可以快速实现表单数据的双向绑…

vue实现表格输出

vue实现表格输出

Vue 实现表格输出的方法 使用原生表格标签 在 Vue 模板中可以直接使用 HTML 原生表格标签(<table>、<tr>、<td>等)渲染数据。通过 v-fo…

vue实现表单窗口

vue实现表单窗口

Vue 实现表单窗口的方法 使用 Vue 组件创建表单 创建一个 Vue 单文件组件(SFC),包含表单元素和提交逻辑。表单可以包含输入框、下拉菜单、复选框等常见元素。 <template&g…

vue实现复杂表格

vue实现复杂表格

Vue 实现复杂表格的方法 在 Vue 中实现复杂表格通常需要结合组件化、动态渲染和数据处理的能力。以下是几种常见的方法和实现技巧: 使用 Element UI 或 Ant Design Vue 的…