美文网首页
纯css实现checkbox多选框样式自定义

纯css实现checkbox多选框样式自定义

作者: 无疆wj | 来源:发表于2019-08-27 15:03 被阅读0次

效果

未选中状态 已选中状态
试一试http://www.jq22.com/webide/

demo

<!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>
  <!-- 1. 引入iconfont图标 -->
  <link rel="stylesheet" href="http://at.alicdn.com/t/font_1372095_k51wphbu33.css">
  <!-- 2. 定义checkbox样式 -->
  <style>
    /* 2.1 重置checkbox多选框的样式 */
    .checkbox {
      margin: 0;
      padding: 0;
      width: 20px;
      height: 20px;
    }

    .checkbox::before {
      content: "";
      font-size: 16px;
      font-weight: 700;
      display: block;
      width: 20px;
      height: 20px;
      line-height: 16px;
      text-align: center;
      box-sizing: border-box;
      border: 2px solid #24acf2;
      background-color: #fff;
    }

    /* 2.2 多选框选中状态的样式 */
    .checkbox:checked::before {
      content: "\e730";
      color: #fff;
      background-color: #24acf2;
    }
  </style>
</head>

<body>
  <!-- 3 html使用结构 -->
  <div>
    <input id="checkbox1" class="iconfont checkbox" type="checkbox" />
    <label for="checkbox1">多选框1</label>
  </div>

  <div>
    <input id="checkbox2" class="iconfont checkbox" type="checkbox" />
    <label for="checkbox2">多选框2</label>
  </div>

  <div>
    <input id="checkbox3" class="iconfont checkbox" type="checkbox" />
    <label for="checkbox3">多选框3</label>
  </div>

</body>

</html>

相关文章

网友评论

      本文标题:纯css实现checkbox多选框样式自定义

      本文链接:https://www.haomeiwen.com/subject/kvqpsctx.html