表单练习
- html
- css
html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>表单练习</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form>
<h2>注册表单</h2>
<!-- 文本输入 -->
<label for="username">用户名:</label>
<input type="text" id="username" name="username" placeholder="请输入用户名">
<!-- 密码 -->
<label for="password">密码:</label>
<input type="password" id="password" name="password" placeholder="请输入密码">
<!-- 单选按钮 -->
<label>性别:</label>
<input type="radio" id="male" name="gender" value="male" class="inline">
<label for="male" class="inline">男</label>
<input type="radio" id="female" name="gender" value="female" class="inline">
<label for="female" class="inline">女</label>
<!-- 多选框 -->
<label>兴趣:</label>
<input type="checkbox" id="coding" name="hobby" value="coding" class="inline">
<label for="coding" class="inline">编程</label>
<input type="checkbox" id="music" name="hobby" value="music" class="inline">
<label for="music" class="inline">音乐</label>
<input type="checkbox" id="sports" name="hobby" value="sports" class="inline">
<label for="sports" class="inline">运动</label>
<!-- 下拉框 -->
<label for="city">城市:</label>
<select id="city" name="city">
<option value="">请选择</option>
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="guangzhou">广州</option>
</select>
<!-- 文本域 -->
<label for="about">自我介绍:</label>
<textarea id="about" name="about" rows="4" placeholder="写点什么..."></textarea>
<!-- 提交按钮 -->
<button type="submit">提交</button>
</form>
</body>
</html>
css
body {
font-family: Arial, sans-serif;
padding: 20px;
background: #f9f9f9;
}
form {
max-width: 400px;
margin: auto;
padding: 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
label {
display: block;
margin-top: 12px;
font-weight: bold;
}
input, select, textarea, button {
margin-top: 6px;
width: 100%;
padding: 8px;
font-size: 14px;
border: 1px solid #ccc;
border-radius: 6px;
}
.inline {
display: inline-block;
width: auto;
margin-right: 10px;
}
button {
background: #4a90e2;
color: white;
font-weight: bold;
cursor: pointer;
border: none;
}
button:hover {
background: #357ab8;
}