css 表单制作
CSS 表单制作方法
使用CSS美化表单元素,提升用户体验和视觉一致性。以下为常见表单组件的样式实现方式:
基础表单结构
<form class="styled-form">
<label for="name">姓名:</label>
<input type="text" id="name" name="name">
<label for="email">邮箱:</label>
<input type="email" id="email" name="email">
<button type="submit">提交</button>
</form>
输入框样式
.styled-form input[type="text"],
.styled-form input[type="email"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 16px;
transition: border-color 0.3s;
}
.styled-form input:focus {
border-color: #4CAF50;
outline: none;
box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
}
标签样式
.styled-form label {
display: block;
margin-top: 15px;
font-weight: bold;
color: #333;
}
按钮样式
.styled-form button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 20px 0;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
transition: background-color 0.3s;
}
.styled-form button:hover {
background-color: #45a049;
}
单选/复选框样式
.styled-form input[type="radio"],
.styled-form input[type="checkbox"] {
margin-right: 10px;
transform: scale(1.2);
}
.styled-form .radio-label,
.styled-form .checkbox-label {
display: inline-block;
margin-right: 20px;
font-weight: normal;
cursor: pointer;
}
下拉选择框样式
.styled-form select {
width: 100%;
padding: 12px 20px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: white;
font-size: 16px;
margin: 8px 0;
}
错误状态样式
.styled-form .error {
color: #ff0000;
font-size: 14px;
margin-top: 5px;
}
.styled-form input.error-border {
border-color: #ff0000;
}
响应式设计

@media screen and (min-width: 600px) {
.styled-form {
max-width: 500px;
margin: 0 auto;
}
.styled-form button {
width: auto;
padding: 14px 40px;
}
}
这些样式可以根据实际需求进行调整,如修改颜色、间距、圆角等属性来匹配网站整体设计风格。






