Html——选项框、立方体与选项框
一、html选项框
1.单选框
name值相同为一个选项,只会有一个内容被选中类型为radio
2.复选框
同一个选项name值要相同,但是可以有多个内容被选上checkbox
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.demo{
width: 100px;
height: 100px;
border: 1px solid red;
}
#bgcolor:checked~.demo{
background-color: skyblue;
}
</style>
<body>
<form action="" method="POST">
女生
<input type="radio" value="女" name="gender" id="bgcolor">
男生
<input type="radio" value="男" name="gender">
<hr>
西瓜<input type="checkbox" value="西瓜" name="fruit" ">
菠萝<input type="checkbox" value="菠萝" name="fruit" >
哈密瓜<input type="checkbox" value="哈密瓜" name="fruit">
<hr>
<input type="submit" value="提交">
<hr>
<div class="demo"></div>
</form>
</body>
</html>
label可以绑定输入框,for绑定选项id
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<style>
.control{
width: 300px;
height: 300px;
margin: 100px auto;
}
.demo {
width: 100px;
height: 100px;
border: 1px solid red;
}
#bgyellow:checked ~ .demo {
background-color: rgb(247, 250, 49);
}
#bgblue:checked ~ .demo {
background-color: rgb(52, 143, 218);
}
#bggreen:checked ~ .demo {
background-color: rgb(92, 250, 184);
}
</style>
<body>
<div class="control">
<form action="" method="POST">
<label for="bgyellow">
选择为黄色
</label>
<label for="bgblue">
选择为蓝色
</label>
<label for="bggreen">
选择为绿色
</label>
<h4>选择你喜欢的颜色</h4>
黄色
<input type="radio" value="黄色" name="gender" id="bgyellow" /><br />
蓝色
<input type="radio" value="蓝色" name="gender" id="bgblue" /><br />
绿色
<input type="radio" value="绿色" name="gender" id="bggreen" /><br />
<div class="demo"></div>
</form>
</div>
</body>
</html>
label设置按钮样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<style>
.control {
width: 600px;
height: 300px;
margin: 100px auto;
}
.demo {
width: 100px;
height: 80px;
}
#bgyellow:checked ~ .demo {
background-color: rgb(247, 250, 49);
}
#bgblue:checked ~ .demo {
background-color: rgb(52, 143, 218);
}
#bggreen:checked ~ .demo {
background-color: rgb(92, 250, 184);
}
label {
/* 本身是行元素设置为行块元素 */
display: inline-block;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
font-family: "宋体";
box-shadow: 0px 0px 0px #424242;
transition: 0.5s;
border-radius: 10px;
margin: 20px;
}
label:hover {
box-shadow: 0px 0px 10px #424242;
}
</style>
<body>
<div class="control">
<form action="" method="POST">
<h4>选择你喜欢的颜色</h4>
<label for="bgyellow">
选择为黄色
</label>
<label for="bgblue">
选择为蓝色
</label>
<label for="bggreen">
选择为绿色
</label>
<input
type="radio"
value="黄色"
name="gender"
id="bgyellow"
hidden
/>
<input
type="radio"
value="蓝色"
name="gender"
id="bgblue"
hidden
/>
<input type="radio" value="绿色" name="gender" id="bggreen" hidden />
<div class="demo"></div>
</form>
</div>
</body>
</html>
二、立方体与选项框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="../css/cubestyle.css" />
</head>
<body>
<div class="control">
<input type="radio" id="front" hidden="hidden" name="selectone" />
<input type="radio" id="back" hidden="hidden" name="selectone" />
<input type="radio" id="left" hidden="hidden" name="selectone" />
<input type="radio" id="right" hidden="hidden" name="selectone" />
<input type="radio" id="top" hidden="hidden" name="selectone" />
<input type="radio" id="bottom" hidden="hidden" name="selectone" />
<input type="radio" id="big" hidden="hidden" name="selectone" />
<input type="radio" id="small" hidden="hidden" name="selectone" />
<div class="cube">
<div class="content front"></div>
<div class="content back"></div>
<div class="content left"></div>
<div class="content right"></div>
<div class="content top"></div>
<div class="content bottom"></div>
</div>
<br />
<br />
<br />
<div class="choose">
<label for="front" class="btn">前面</label>
<label for="back" class="btn">后面</label>
<label for="left" class="btn">左面</label>
<label for="right" class="btn">右面</label>
<label for="top" class="btn">上面</label>
<label for="bottom" class="btn">下面</label>
<label for="small" class="btn">缩小</label>
<label for="big" class="btn">放大</label>
</div>
</div>
</body>
</html>
body {
perspective: 1000px;
}
.control {
margin: 100px auto;
}
.cube {
margin: 0px auto;
width: 100px;
height: 100px;
position: relative;
transform-style: preserve-3d;
transform: rotate3d(1, 1, 1, 0deg);
transition: all 5s;
}
.cube:hover {
transform: rotate3d(0, 1, 1, 720deg);
}
.content {
position: absolute;
opacity: 0.6;
left: 0;
top: 0;
width: 100px;
height: 100px;
}
.front {
background-image: url("../imag/a.jpg");
background-size: 100% auto;
transform: translateZ(50px);
}
.back {
background-image: url("../imag/b.jpg");
background-size: 100% auto;
transform: translateZ(-50px);
}
.left {
background-image: url("../imag/c.jpeg");
background-size: auto 100%;
transform: rotateY(-90deg) translateZ(50px);
}
.right {
background-image: url("../imag/f.jpeg");
background-size: auto 100%;
transform: rotateY(90deg) translateZ(50px);
}
.top {
background-image: url("../imag/d.jpg");
background-size: auto 100%;
transform: rotateX(90deg) translateZ(50px);
}
.bottom {
background-image: url("../imag/e.jpeg");
background-size: auto 100%;
transform: rotateX(-90deg) translateZ(50px);
}
.choose {
width: 700px;
height: 100px;
text-align: center;
margin: 0 auto;
}
.btn {
width: 80px;
height: 40px;
font-size: 20px;
color: #424242;
border-radius: 10px;
border: 1px solid #ccc;
text-align: center;
line-height: 40px;
display: inline-block;
}
#front:checked ~ .cube {
transform: rotate3d(0, 0, 0, 0deg);
}
#back:checked ~ .cube {
transform: rotate3d(0, 1, 0, 180deg);
}
#left:checked ~ .cube {
transform: rotate3d(0, 1, 0, 90deg);
}
#right:checked ~ .cube {
transform: rotate3d(0, 1, 0, -90deg);
}
#top:checked ~ .cube {
transform: rotate3d(1, 0, 0, 90deg);
}
#bottom:checked ~ .cube {
transform: rotate3d(1, 0, 0, -90deg);
}
#big:checked ~ .cube {
transform: scale(1.3) rotate3d(1, 0, 0, -90deg);
}
#small:checked ~ .cube {
/* 放大倍数translateZ() */
transform: scale(0.5) rotate3d(1, 0, 0, -90deg);
}
#front:checked ~ .choose [for="front"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#back:checked ~ .choose [for="back"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#left:checked ~ .choose [for="left"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#right:checked ~ .choose [for="right"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#top:checked ~ .choose [for="top"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#bottom:checked ~ .choose [for="bottom"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#big:checked ~ .choose [for="big"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}
#small:checked ~ .choose [for="small"] {
background: #ccc;
box-shadow: 0 0 10px #424242;
color: #fff;
}