<…">
当前位置:首页 > CSS

css表格表单制作

2026-01-08 19:09:12CSS

CSS表格制作

使用CSS创建表格主要涉及<table>标签及其子元素的样式控制。以下是一个基础示例:

<table class="styled-table">
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1 Cell 1</td>
      <td>Row 1 Cell 2</td>
    </tr>
  </tbody>
</table>
.styled-table {
  width: 100%;
  border-collapse: collapse;
  margin: 25px 0;
  font-size: 0.9em;
  font-family: sans-serif;
}

.styled-table th,
.styled-table td {
  padding: 12px 15px;
  border: 1px solid #dddddd;
}

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

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

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

CSS表单制作

表单样式设计通常涉及<form>元素及其输入控件的样式定制:

css表格表单制作

<form class="styled-form">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">

  <label for="email">Email:</label>
  <input type="email" id="email" name="email">

  <button type="submit">Submit</button>
</form>
.styled-form {
  max-width: 400px;
  margin: 0 auto;
  padding: 20px;
  background: #f9f9f9;
  border-radius: 5px;
}

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

.styled-form input[type="text"],
.styled-form input[type="email"] {
  width: 100%;
  padding: 8px;
  margin-bottom: 15px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.styled-form button {
  background-color: #4CAF50;
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.styled-form button:hover {
  background-color: #45a049;
}

响应式表格设计

针对移动设备的表格响应式处理:

css表格表单制作

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

  .responsive-table thead {
    display: none;
  }

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

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

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

表单验证样式

使用CSS伪类为表单添加验证反馈:

.styled-form input:valid {
  border-color: #4CAF50;
}

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

.styled-form input:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);
}

高级表格样式技巧

实现斑马纹和悬停效果的组合:

.striped-table tbody tr:nth-child(odd) {
  background-color: #f2f2f2;
}

.striped-table tbody tr:hover {
  background-color: #e6e6e6;
  transition: background-color 0.3s ease;
}

这些代码示例展示了如何使用CSS创建美观且功能完善的表格和表单,包括响应式设计、验证样式和交互效果。根据实际需求可以调整颜色、间距和动画效果等参数。

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

相关文章

vue实现表格上传头像

vue实现表格上传头像

实现表格上传头像功能 在Vue中实现表格上传头像功能,可以通过以下步骤完成。这里假设使用Element UI作为UI框架,但方法同样适用于其他UI库或原生实现。 安装必要依赖 确保项目中已安装El…

vue实现动态用户表格

vue实现动态用户表格

Vue 动态用户表格实现方法 基础表格结构 使用<table>或第三方组件库(如Element UI的el-table)构建基础框架。静态数据示例: <template>…

jquery表单

jquery表单

jQuery 表单操作 jQuery 提供了丰富的 API 用于表单操作,包括表单元素的选择、值获取与设置、事件处理等。 表单元素选择 使用 jQuery 选择器可以方便地选取表单元素: //…

vue实现表格复选

vue实现表格复选

实现表格复选的基本思路 在Vue中实现表格复选功能,通常需要结合v-model绑定选中状态,监听复选框变化事件,以及维护一个选中项的数组。以下是具体实现方法: 基础实现步骤 数据准备 定义表格数据…

css制作表格

css制作表格

CSS 制作表格的方法 使用 CSS 可以灵活地创建和样式化表格,以下是几种常见的方法: 使用 HTML 表格标签结合 CSS 样式 通过 HTML 的 <table>、<tr&g…

vue 实现跨行表格

vue 实现跨行表格

实现跨行表格的方法 在Vue中实现跨行表格可以通过多种方式完成,以下是几种常见的方法: 使用HTML原生表格 HTML原生表格支持rowspan属性,可以直接在Vue模板中使用: <tabl…