第七章:表单和交互
综合示例:
HTML:
<form class="contact-form">
<div class="form-group">
<label for="name">姓名:</label>
<input type="text" id="name" required>
</div>
<div class="form-group">
<label for="email">邮箱:</label>
<input type="email" id="email" required>
</div>
<button type="submit">提交</button>
</form>
CSS:
.contact-form {
max-width: 400px;
margin: 0 auto;
padding: 20px;
}
.form-group {
margin-bottom: 15px;
}
input {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
input:focus {
outline: none;
border-color: #2563eb;
box-shadow: 0 0 0 2px rgba(37,99,235,0.2);
}
button {
width: 100%;
padding: 10px;
background: #2563eb;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
HTML编辑器
CSS编辑器
预览结果