用css改变默认的checkbox样式
2015-08-05 21:38
726 查看
自己常用的改变checkbox样式的两个方法:
一.利用background用图片代替checkbox效果
缺点:你首先得有一张好看的图片
优点:浏览器兼容性好
二.利用css的:after跟transform属性代替checkbox效果
优点:不需要图片,纯css搞定
缺点:兼容性,不用说你也知道我指的是哪个奇葩浏览器
一.利用background用图片代替checkbox效果
缺点:你首先得有一张好看的图片
优点:浏览器兼容性好
<!doctype html> <html> <head> <meta charset="utf-8"> <title>chec</title> <style> #wrapper {margin: 20px auto;} #wrapper .input_check {position: absolute;width: 20px;height: 20px;visibility: hidden;} #wrapper span {position: relative;} #wrapper .input_check+label {display: inline-block;width: 20px;height: 20px;background: url(checkbox2.png) no-repeat;background-position: -31px -3px;} #wrapper .input_check:checked+label {background-position: -5px -3px;} </style> </head> <body> <h3>利用background用图片代替checkbox效果</h3> <div id="wrapper"> <span><input type="checkbox"class="input_check" id="check1"><label for="check1"></label></span> <span><input type="checkbox"class="input_check" id="check2"><label for="check2"></label></span> </div> </body> </html>
二.利用css的:after跟transform属性代替checkbox效果
优点:不需要图片,纯css搞定
缺点:兼容性,不用说你也知道我指的是哪个奇葩浏览器
<!doctype html> <html> <head> <meta charset="utf-8"> <title>chec</title> <style> #container {margin: 20px auto;} #container span {position: relative;} #container .input_check {position: absolute;visibility: hidden;} #container .input_check+label {display: inline-block;width: 16px;height: 16px;border: 1px solid #fd8845;} #container .input_check:checked+label:after {content: "";position: absolute;left: 2px;bottom: 12px;width: 9px;height: 4px; border: 2px solid #fd8845;border-top-color: transparent;border-right-color: transparent; -ms-transform: rotate(-60deg); -moz-transform: rotate(-60deg); -webkit-transform: rotate(-60deg); transform: rotate(-45deg);} </style> </head> <body> <h3>利用css的:after跟transform属性代替checkbox效果</h3> <div id="container"> <span><input type="checkbox"class="input_check" id="check3"><label for="check3"></label></span> <span><input type="checkbox"class="input_check" id="check4"><label for="check4"></label></span> </div> </body> </html>
相关文章推荐
- 在引入的css或者js文件后面加参数的作用
- 关于css position 的 static、relative、absolute、fixed、inherit
- CSS3响应式滑动菜单
- 高质量CSS
- 利用CSS3的transition属性实现滑动效果
- 根据数据显示行的样式
- CSS的font-size属性及其em值的使用
- @keyframes规则实现多重背景的CSS动画
- 三列等高 css实现
- ProgressDialog的样式
- 使用CSS实现文字的竖排的简单方法
- Emmet:HTML/CSS代码快速编写神器
- IE和Firefox浏览器CSS兼容性技巧整理
- 纯CSS3实现的8种Loading动画效果
- 使用CSS绘制星级评分效果的方法
- CSS3圆圈旋转的样式
- css常用技巧
- css 画基本图形
- css之自己对hack的理解
- css3 - 旋转的木马