温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用CSS3美化单选、复选按钮的显示样式

发布时间:2021-06-29 13:43:09 来源:亿速云 阅读:160 作者:小新 栏目:web开发

这篇文章将为大家详细讲解有关如何使用CSS3美化单选、复选按钮的显示样式,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

效果图如下

如何使用CSS3美化单选、复选按钮的显示样式

实例代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>复选单选样式</title>
    <link rel="stylesheet" href="style.css">
</head>
<style>
    form {
      border: 1px solid #ccc;
      padding: 20px;
      width: 300px;
    }
    .wrapper {
      margin-bottom: 10px;
    }
    /*复选框*/
    .checkbox-box {
      display: inline-block;
      width: 20px;
      height: 20px;
      margin-right: 10px;
      position: relative;
      border: 2px solid orange;
      vertical-align: middle;
    }
    .checkbox-box input {
      opacity: 0;
      position: absolute;
      top:0;
      left:0;
      z-index:10;
    }
    .checkbox-box span {
      position: absolute;
      top: -10px;
      right: 3px;
      font-size: 30px;
      font-weight: bold;
      font-family: Arial;
      -webkit-transform: rotate(30deg);
      transform: rotate(30deg);
      color: orange;
    } 
    .checkbox-box input[type="checkbox"] + span {
      opacity:0;
    }
    .checkbox-box input[type="checkbox"]:checked + span {
      opacity: 1;
    }

    /*单选框*/
    .redio-box {
      display: inline-block;
      width: 30px;
      height: 30px;
      margin-right: 10px;
      position: relative;
      background: orange;
      vertical-align: middle;
      border-radius: 100%;
    }
    .redio-box input {
      opacity: 0;
      position: absolute;
      top:0;
      left:0;
      width: 100%;
      height:100%;
      z-index:100;/*使input按钮在span的上一层,不加点击区域会出现不灵敏*/
    }
    .redio-box span { 
      display: block;
      width: 10px;
      height: 10px;
      border-radius: 100%;
      position: absolute;
      background: #fff;
      top: 50%;
      left:50%;
      margin: -5px 0  0 -5px;
      z-index:1;
    }
    .redio-box input[type="radio"] + span {
      opacity: 0;
    }
    .redio-box input[type="radio"]:checked + span {
      opacity: 1;
    }
</style>
<body>
<h3>复选框:</h3>
<form action="#">

  <div class="wrapper">
    <div class="checkbox-box">
      <input name="1" type="checkbox" checked id="usename" />
      <span>&radic;</span>
    </div>
    <label for="usename">体育</label>
  </div>
  
  <div class="wrapper">
    <div class="checkbox-box">
      <input name="1" type="checkbox"  id="usepwd" />
      <span>&radic;</span>
    </div>
    <label for="usepwd">音乐</label>
  </div>

  <div class="wrapper">
    <div class="checkbox-box">
      <input name="1" type="checkbox"  id="checkbox3" />
      <span>&radic;</span>
    </div>
    <label for="checkbox3">读书</label>
  </div>
  
  <div class="wrapper">
    <div class="checkbox-box">
      <input name="1" type="checkbox"   id="checkbox4" />
      <span>&radic;</span>
    </div>
    <label for="checkbox4">运动</label>
  </div>

</form> 


<h3>单选框</h3>
<form action="#">
  <div class="wrapper">
    <div class="redio-box">
      <input type="radio" checked="checked"  id="boy" name="1" /><span></span>
    </div>
    <label for="boy">男</label>
  </div>
  
  <div class="wrapper">
    <div class="redio-box">
      <input type="radio"  id="girl" name="1" /><span></span>
    </div>
    <label for="girl">女</label>
  </div>
</form> 

</body>
</html>

注意:

+  是css的相邻选择符。

关系选择符只有四种,是 空格  >  +   ~ (包含选择符、子选择符、相邻选择符、兄弟选择符)

关于“如何使用CSS3美化单选、复选按钮的显示样式”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI