HTML5&CSS3的CheckBox美化案例

2017-03-07  本文已影响0人  HAXXY

属性介绍:transition (过渡效果)

transition-property 规定所设置的CSS过渡名称
transition-duration 设置过渡所需要的时间 如果设置为0则没有效果
transition-timing-function 设置过渡效果的速度曲线
transition-delay 定义过渡效果何时开始

transition: all 0 ease 0 //默认属性  

transition-timing-function 属性描述

描述
linear 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。
ease 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。
ease-in 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。
ease-out 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。
cubic-bezier(n,n,n,n) 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。

公共CSS样式代码

//隐藏Type属性为checkbox的input框
input[type=checkbox] {
    visibility: hidden;
}

样式一

/* 第一种样式 */
.checkboxOne {//制作一个横条
    width: 40px;
    height: 10px;
    background: #555;
    margin: 20px 80px;
    position: relative;
    border-radius: 3px;
}
/**
 * Create the slider from the label
 */
.checkboxOne label {
    display: block;//定义为块级元素
    width: 16px;
    height: 16px;
    border-radius: 50%;
    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -o-transition: all .5s ease;
    -ms-transition: all .5s ease;
    transition: all .5s ease;//设置滑块动作的速度
    cursor: pointer;
    position: absolute;//绝对定位
    top: -3px;
    left: -3px;
    background: #ccc;
}
/**
 * Move the slider in the correct position if the checkbox is clicked
 */
.checkboxOne input[type=checkbox]:checked + label {
    left: 27px;//设置label滑块移动的距离
}

HTML代码

通过label的for属性与checkbox进行绑定实现选择功能

<section>
   <!-- HTML代码 -->
   <h3>Checkbox One</h3>
   <div class="checkboxOne">
     <input type="checkbox" value="1" id="checkboxOneInput" name="" />
     <label for="checkboxOneInput"></label>
   </div>
</section>
上一篇下一篇

猜你喜欢

热点阅读