纯CSS实现多选组件

mark: http://blog.meathill.com/tech/fe/create-multiple-select-component-with-pure-css.html

Demo: 

小宝3225 王老白白白 空夫31 谷大白话 Meathill 一毛不拔大师

 Code:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
  #container {
    display:flex;
    flex-direction:row;
    flex-wrap:wrap;
  }
  #container input,
  #container label {
    order: 2;
  }
  input[type=checkbox]:checked,
  input[type=checkbox]:checked + label {
    order: 0 !important;
  }
  hr {
    display:none;
    order: 1;
    width:100%;
  }
  input[type=checkbox]:checked ~ hr {
    display:block;
  }
  input[type=checkbox] {
    display: none;
  }
  label {
    min-width: 120px;
    border: 1px solid #CCC;
    padding: 2px 8px;
    text-align: center;
    margin: 0 5px 5px 0;
    background: #FFF;
    color: #333;
    border-radius: 3px;
    box-sizing: border-box;
  }
  label:hover {
    border-color: #ADADAD;
    background: #EBEBEB;
    cursor: pointer;
  }
  input[type=checkbox]:checked + label {
    order: 0;
    background-color: #428BCA;
    border-color: #357EBD;
    color: #FFF;
  }
  input[type=checkbox]:checked + label:hover {
    background-color: #327681;
    border-color: #285E8E;
  }
  label:before {
    display: inline;
    content: "+ ";
    font-size: 100%;
  }
  input[type=checkbox]:checked + label:before {
    display: inline;
    content: "- ";
    font-size: 100%;
  }
  input[type=checkbox]:checked + label {
    -webkit-transition: background-color 1s;
    -moz-transition: background-color 1s;
    -ms-transition: background-color 1s;
    -o-transition: background-color 1s;
    transition: background-color 1s;
  }
  </style>
</head>
<body>
  <div id="container">
      <input type="checkbox" name="q[]" id="q1">
      <label for="q1">小宝3225</label>
      <input type="checkbox" name="q[]" id="q2">
      <label for="q2">王老白白白</label>
      <input type="checkbox" name="q[]" id="q3">
      <label for="q3">空夫31</label>
      <input type="checkbox" name="q[]" id="q4">
      <label for="q4">谷大白话</label>
      <input type="checkbox" name="q[]" id="q5">
      <label for="q5">Meathill</label>
      <input type="checkbox" name="q[]" id="q6">
      <label for="q6">一毛不拔大师</label>
      <hr>
  </div>
</body>
</html>

 

转载于:https://www.cnblogs.com/yedeying/p/3675001.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值