HTML5&CSS3的CheckBox美化案例

属性介绍: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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 5,794评论 0 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 6,831评论 0 11
  • 转载请声明 原文链接 关注公众号获取更多资讯 这篇文章主要总结H5的一些新增的功能以及一些基础归纳,这里只是一个提...
    前端进阶之旅阅读 12,954评论 22 225
  • 变形--旋转 rotate() 旋转rotate()函数通过指定的角度参数使元素相对原点进行旋转。它主要在二维空间...
    阿振_sc阅读 4,423评论 1 5
  • 1.CSS3 边框 border-radius CSS属性用来设置边框圆角。当使用一个半径时确定一个圆形;当使用两...
    garble阅读 3,919评论 0 0