原创

纯css美化的input,radio,CheckBox等【单选框复选框】


很多时候我们在写表单的时候,不想使用css框架,那就只能自己动手去美化单选框、复选框等样式,这里我给大家整理了纯css美化的单选框和复选框提供给大家使用。

著作权归原作者所有。

样式预览:

在线预览:http://micuer.com/yuanma/radioDemo.html

  1. <style type="text/css">
  2. body {
  3. font: 16px/150% microsoft yahei,pingfang sc,Tahoma,Sim sun;
  4. }
  5. input:disabled + label {/*禁用的指针*/
  6. cursor: not-allowed
  7. }
  8. .Radio input,
  9. .Checkbox input {
  10. display: none
  11. }
  12. .Radio label,
  13. .Checkbox label {
  14. padding: 0 16px 0 0;
  15. display: inline-block;
  16. cursor: pointer;
  17. position: relative
  18. }
  19. .Radio label:before,
  20. .Checkbox label:before {
  21. box-sizing: border-box;
  22. content: "";
  23. width: 18px;
  24. height: 18px;
  25. border-radius: 50%;
  26. border: 1px solid #999;
  27. margin: 0 8px;
  28. vertical-align: middle;
  29. display: inline-block;
  30. transition: 0.1S;
  31. }
  32. .Radio label:hover:before,
  33. .Checkbox label:hover:before {
  34. border-color: #00a4ff;
  35. }
  36. .Radio input:disabled + label:before,
  37. .Checkbox input:disabled + label:before {
  38. background-color: #CCC;
  39. border-color: #999;
  40. opacity: 0.5;
  41. }
  42. .Radio input:disabled + label,
  43. .Checkbox input:disabled + label {
  44. opacity: 0.5;
  45. }
  46. .Radio input:checked + label:before {
  47. border: 5px solid #00a4ff;
  48. }
  49. .Checkbox label:before {
  50. background: url(images/ico_tick.svg) no-repeat center;
  51. background-size: 0;
  52. border-radius: 4px;
  53. transition: 0.2S;
  54. }
  55. .Checkbox input:checked + label:before {
  56. background-color: #00a4ff;
  57. background-size: 16px;
  58. border-color: #00a4ff;
  59. }
  60. .HoverLabel label {
  61. display: block;
  62. border-radius: 4px;
  63. padding: 4px;
  64. width: 100%;
  65. }
  66. .HoverLabel label:hover {
  67. background-color: #EEE;
  68. }
  69. </style>

html

  1. <h3>单选框类型</h3>
  2. <h4>基础样式</h4>
  3. <span class="Label"><span class="Mandatory"></span>请选择性别</span>
  4. <span class="Radio">
  5. <input id="man" name="sex" type="radio" checked /><label for="man"></label>
  6. <input id="female" name="sex" type="radio" /><label for="female"></label>
  7. <input id="secret" name="sex" type="radio" disabled /><label for="secret">不可用</label>
  8. </span>
  9. <h4>垂直样式</h4>
  10. <ul class="Radio">
  11. <li class="Black">未取得驾驶证的学员在道路上学习驾驶技能,下列哪种做法是正确的?</li>
  12. <li>
  13. <input id="safe1" name="safe" type="radio" /><label for="safe1">A. 使用所学车型的教练车由非教练员的驾驶人随车指导</label>
  14. </li>
  15. <li>
  16. <input id="safe2" name="safe" type="radio" /><label for="safe2">B. 使用所学车型的教练车单独驾驶学习</label>
  17. </li>
  18. <li>
  19. <input id="safe3" name="safe" type="radio" /><label for="safe3">C. 使用私家车由教练员随车指导</label>
  20. </li>
  21. <li>
  22. <input id="safe4" name="safe" type="radio" /><label for="safe4">D. 使用所学车型的教练车由教练员随车指导</label>
  23. </li>
  24. </ul>
  25. <div style="height: 100px"><!--就是个间隔没有什么用--></div>
  26. <h3>复选框类型</h3>
  27. <h4>基础样式</h4>
  28. <span class="Checkbox">
  29. <input id="love1" type="checkbox" checked /><label for="love1">宽带</label>
  30. <input id="love2" type="checkbox" /><label for="love2">iTV</label>
  31. <input id="love3" type="checkbox" /><label for="love3">固话</label>
  32. <input id="love4" type="checkbox" disabled checked /><label for="love4">已选不可用</label>
  33. <input id="love5" type="checkbox" disabled /><label for="love5">未选不可用</label>
  34. </span>
  35. <h4>垂直样式</h4>
  36. <ul class="Checkbox HoverLabel">
  37. <li class="Dot Bold">机动车在道路上变更车道需要注意什么?</li>
  38. <li>
  39. <input id="safe21" name="safe" type="checkbox" /><label for="safe21">A. 尽快加速进入左侧车道</label>
  40. </li>
  41. <li>
  42. <input id="safe22" name="safe" type="checkbox" /><label for="safe22">B. 开启转向灯迅速向左转向</label>
  43. </li>
  44. <li>
  45. <input id="safe23" name="safe" type="checkbox" /><label for="safe23">C. 进入左侧车道时适当减速</label>
  46. </li>
  47. <li>
  48. <input id="safe24" name="safe" type="checkbox" /><label for="safe24">D. 不能影响其他车辆正常行驶</label>
  49. </li>
  50. </ul>
留言反馈
问题反馈渠道,如有软件无法下载或者其他问题可反馈。【由于某种原因,目前留言不展示】
用户需要登录后才能留言反馈