Label绑定输入框
for绑定输入框的id
绑定输入框的id后,就可以在label标签中调用id值相同的元素框
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" type="text/css" href="CSS_style/style_color.css">
</head>
<body>
<form action="" method="post">
<label class="btn" for="yellow">点击这里变为黄色</label><br>
<label class="btn" for="blue">点击这里变为蓝色</label><br>
<label class="btn" for="green">点击这里变为绿色</label><br>
<h3>请选择你喜欢的颜色:</h3>
<input type="checkbox" name="color" id="yellow" value="黄色" hidden="hidden">
<input type="checkbox" name="color" id="green" value="绿色" hidden="hidden">
<input type="checkbox" name="color" id="blue" value="蓝色" hidden="hidden">
<div id="d1">
</div>
</form>
</body>
</html>
css文件
#d1{
width: 300px;
height: 400px;
border: 1px solid #999;
}
#yellow:checked~#d1{
background: yellow;
}
#green:checked~#d1{
background: green;
}
#blue:checked~#d1{
background: blue;
}
.btn{
display: inline-block;
width: 30x;
height: 40px;
margin: 50px;
text-align: center;
line-height: 100px;
border-radius: 30px;
border: 1px solid #ccc;
transition: 0.5s;
}
.btn:hover{
box-shadow: 0 0 30px #999;
}