Html——选项框、立方体与选项框

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;
}

在这里插入图片描述

  • 1
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可可鸭~

想吃糖~我会甜

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值