当前位置:首页 > CSS

css表格表单制作

2026-02-27 00:07:23CSS

CSS表格表单制作

表格制作

使用CSS可以美化HTML表格,使其更符合设计需求。以下是一个简单的表格样式示例:

<table class="styled-table">
  <thead>
    <tr>
      <th>姓名</th>
      <th>年龄</th>
      <th>职业</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>张三</td>
      <td>25</td>
      <td>设计师</td>
    </tr>
    <tr>
      <td>李四</td>
      <td>30</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可以大幅提升表单的视觉效果和用户体验。以下是一个表单样式示例:

<form class="styled-form">
  <div class="form-group">
    <label for="name">姓名</label>
    <input type="text" id="name" name="name" required>
  </div>

  <div class="form-group">
    <label for="email">电子邮箱</label>
    <input type="email" id="email" name="email" required>
  </div>

  <div class="form-group">
    <label for="message">留言</label>
    <textarea id="message" name="message" rows="4" required></textarea>
  </div>

  <button type="submit">提交</button>
</form>
.styled-form {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  background-color: #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: 8px;
  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;
  transition: border-color 0.3s;
}

.styled-form input[type="text"]:focus,
.styled-form input[type="email"]:focus,
.styled-form textarea:focus {
  border-color: #009879;
  outline: none;
}

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

响应式设计

为适应不同设备屏幕尺寸,可以添加媒体查询:

css表格表单制作

@media (max-width: 768px) {
  .styled-table {
    font-size: 0.8em;
    min-width: auto;
  }

  .styled-form {
    padding: 15px;
  }
}

这些示例展示了如何使用CSS创建美观且功能完善的表格和表单,通过调整颜色、间距、边框等属性可以实现各种设计风格。

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

相关文章

vue表格实现单选框

vue表格实现单选框

Vue 表格实现单选框的方法 在 Vue 中实现表格单选框功能,可以通过结合 el-table(Element UI)或原生表格与 Vue 的数据绑定特性完成。以下是几种常见实现方式: 使用 Ele…

vue表格实现单选

vue表格实现单选

实现 Vue 表格单选功能 使用 v-model 绑定选中状态 在表格的每一行添加单选按钮或点击行触发选中,通过 v-model 绑定一个变量存储当前选中行的唯一标识(如 id)。 示例代码: &l…

如何封装表单react

如何封装表单react

封装 React 表单的方法 封装 React 表单可以通过创建可复用的表单组件或自定义 Hook 来实现。以下是几种常见的方法: 使用受控组件封装表单 通过状态管理表单数据,将表单字段的值与 Re…

vue实现表格界面

vue实现表格界面

Vue 实现表格界面的方法 使用 Element UI 的表格组件 Element UI 提供了功能丰富的表格组件,适合快速开发表格界面。安装 Element UI 后,可以直接使用 el-table…

vue表单实现全选

vue表单实现全选

Vue 表单实现全选功能 在 Vue 中实现表单全选功能,通常涉及一个全选复选框和多个子复选框。以下是实现方法: 基本实现 数据绑定 使用 v-model 绑定全选复选框和子复选框的状态,子复选框…

vue实现表格滑动

vue实现表格滑动

Vue实现表格滑动的方法 使用CSS overflow属性实现横向滑动 在表格外层容器设置overflow-x: auto,限制表格宽度超出时出现滚动条。这种方法适合简单场景,无需额外依赖库。 &l…