Drcus | 王亚振

Drcus | 王亚振

随便写,记录点东西

CSS3 checkbox 效果

发布于:  

预览

checkbox

仿原生checkbox:

checkbox checkbox

结构

  <span class="ckbox-component">
    <input type="checkbox" id="ckbox-input">
    <label for="ckbox-input"></label>
  </span>

样式

.ckbox-component input  {
  width: 1px;
  height: 1px;
  position: fixed;
  visibility: hidden;
}

.ckbox-component label {
  border: 1px solid #ccc;
  width: 20px;
  height: 20px;
  display: inline-block;
}
.ckbox-component label:after {
  content: '';
  width: 8px;
  height: 5px;
  display: inline-block;
  margin: 0 0 5px 5px;
  border-left: 2px solid #ccc;
  border-bottom: 2px solid #ccc;
  transform: rotate(-45deg)
}
.ckbox-component input:checked + label:after {
  border-color: #000;
}

丰满的椭圆形 checkbox:

checkbox

结构

  <span class="ckbox-component">
    <input type="checkbox" id="ckbox-input">
    <label for="ckbox-input"></label>
    <div></div>
  </span>

样式

.ckbox-component {
  width: 100px;
  height: 40px;
  display: inline-block;
  position: relative;
}
.ckbox-component div {
  width: 100%;
  height: 100%;
  background-color: #d3d3d3;
  margin-top: -20px;
  border-radius: 20px;
}
.ckbox-component input  {
  width: 1px;  
  visibility: hidden;
}

.ckbox-component label {  
  position: absolute;
  top: 6px;  
  left: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: white;
  transition: left .5s ease;
}

.ckbox-component input:checked + label {
  left: 62px;
}
.ckbox-component input:checked ~ div {
  background-color: #4fbe79;
}

扁平的方形 checkbox:

checkbox

结构

  <span class="ckbox-component">
    <input type="checkbox" id="ckbox-input">
    <label for="ckbox-input"></label>
    <div></div>
  </span>

样式

.ckbox-component {
  width: 100px;
  height: 40px;
  display: inline-block;
  position: relative;
}
.ckbox-component div {
  width: 100%;
  height: 100%;
  background-color: #4fbe79;
  margin-top: -20px;  
}
.ckbox-component input  {
  width: 1px;  
  visibility: hidden;
}

.ckbox-component label {  
  position: absolute;
  top: 6px;  
  left: 8px;
  width: 30px;
  height: 30px;  
  background-color: white;
  transition: left .5s ease;
}
.ckbox-component label:before {
  content: '|||';
  position: absolute;
  left: 6px;
  top: 2px;
  color: #ccc;
  letter-spacing: 3px;
}

.ckbox-component input:checked + label {
  left: 62px;
}
.ckbox-component input:checked ~ div {
  background-color: #e9513a;
}

正圆形 checkbox:

checkbox

结构

  <span class="ckbox-component">
    <input type="checkbox" id="ckbox-input">
    <label for="ckbox-input"></label>    
  </span>

样式

.ckbox-component {
  width: 40px;
  height: 40px;
  display: inline-block;
  background-color: #ccc;
  position: relative;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0, .5);
}
.ckbox-component input  {
  width: 1px;  
  visibility: hidden;
}

.ckbox-component label {  
  position: absolute;
  top: 5px;  
  left: 5px;
  width: 30px;
  height: 30px;  
  border-radius: 50%;
  background-color: #a5a5a5;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5);
  transition: all .3s ease;
}

.ckbox-component input:checked + label {
  background-color: #26ca28;
}

后续碰到有意思的再更新。。。

厚颜一下 ~^_^~

赏赐