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

css表格表单制作

2026-03-31 23:22:08CSS

CSS表格制作

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

css表格表单制作

<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: 600px;
  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;
    border-bottom: 1px dotted #ccc;
  }

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

表单验证样式

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

.styled-form input:invalid,
.styled-form textarea:invalid {
  border-color: #ff6b6b;
}

.styled-form input:valid,
.styled-form textarea:valid {
  border-color: #51cf66;
}

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

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

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

相关文章

css好看的表格制作

css好看的表格制作

使用CSS制作美观表格的方法 边框与间距优化 通过border-collapse属性合并边框,避免双边框效果。设置padding增加单元格内边距,提升可读性。 table { border-…

css表格制作

css表格制作

CSS表格制作方法 使用CSS创建表格可以通过多种方式实现,以下是常见的几种方法: 使用HTML原生表格标签结合CSS样式 <table class="styled-table">…

vue表格实现导出

vue表格实现导出

使用 vue-json-excel 插件 安装插件: npm install vue-json-excel --save 在组件中引入并注册: import JsonExcel from 'vue…

vue实现动态表单

vue实现动态表单

Vue 动态表单实现方法 使用 v-for 动态渲染表单字段 通过遍历数组动态生成表单项,数据驱动视图变化。表单字段配置可存储在数组中,修改数组即可实现表单动态更新。 <template>…

表格制作css

表格制作css

CSS表格样式设计 基础表格样式 通过border-collapse合并边框,使表格更整洁。width控制整体宽度,text-align设置文字对齐方式。 table { border-coll…

怎么制作css表格

怎么制作css表格

制作CSS表格的方法 使用HTML表格标签结合CSS样式 通过HTML的<table>、<tr>、<td>等标签创建表格结构,再使用CSS美化样式。例如: <…