仿复选框样式

梦里梦外; 2022-06-08 04:20 365阅读 0赞

相信大家在看到很多炫酷的网页时总会看到样式很棒的复选框,于是 脑补下代码“input[‘type=”checkbox”’]:padding:10px;border:1px solid red; background:black;…”,完后,一检查人家的代码,立刻懵逼。

废话不多说,我来了,拯救你的无知。

原理: 利用 label 这一特性 自动聚焦到复选框

css样式

  1. <style> input{ margin-bottom: 20px; padding: 10px; background-color: transparent; border: none; font-size: 15px; border-bottom: 1px solid rgba(238, 238, 238, 0.41); outline: none; /* 清除 点击input 的边框*/ color: #FFF; } input[type="checkbox" ] { display: none;} label{ position: relative; padding-left: 30px; border: #F0F8FF; display: inline-block; font-size: 13px; /*background: red;*/ color: #fff; } input[type="checkbox"] + label span{ width: 17px; height: 17px; display: inline-block; border: 1px solid #fff; position: absolute; top: -3px; left: 0; } input[type="checkbox"]:checked + label span::before{ content: ""; background: url(img/tick.png) no-repeat; position: absolute; left: 3px; top: 3px; font-size: 10px; width: 10px; height: 10px; } </style>

html 样式

  1. <body>
  2. <div class="container">
  3. <form action="">
  4. <input type="" name="" id="" placeholder="用户名" /><br><br>
  5. <p>
  6. <input type="checkbox" id="res"/>
  7. <label for="res"><span></span>记住我</label>
  8. </p>
  9. </form>
  10. </div>
  11. </body>

效果图如下:
样式效果

点击后的效果图

发表评论

表情:
评论列表 (有 0 条评论,365人围观)

还没有评论,来说两句吧...

相关阅读

    相关 仿样式

    相信大家在看到很多炫酷的网页时总会看到样式很棒的复选框,于是 脑补下代码“input\[‘type=”checkbox”’\]:padding:10px;border:1px

    相关 伪类改变样式

    大家在开发的过程中,肯定都用过复选框,那么大家有没有为了改变样式而烦恼过? 这里给大家介绍特别简单的一种方式。 话不多说,上代码。 <!DOCTYPE html>