css 设置 checkbox复选框控件的对勾√样式

css 设置 checkbox复选框控件的对勾√样式

最终的样式,想要的效果:
技术分享
 

我们要创建方框中的对勾,对于这一点,我们可以使用伪类创建一个新的元素,为了实现这个样式,我们可以创建一个5px * 15px的长方形并给他加上边框。这时候我们去掉上面和右边的边框之后,它会看起来像一个字母L。然后我们可以使用CSS的属性让它旋转一下,这样看起来就像是一个对勾。

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>选中标签forcheck</title>
    6. <style type="text/css">
    7. .div-checked label {
    8. cursor: pointer;
    9. position: relative;
    10. display: inline-block;
    11. width: 150px;
    12. height: 38px;
    13. border: 1px solid grey;
    14. }
    15. /**
    16. * 按钮透明
    17. * @type {String}
    18. */
    19. input[type="checkbox"] {
    20. opacity: 0;
    21. }
    22. /**
    23. * checkbox选中样式
    24. * @type {String}
    25. */
    26. input[type="checkbox"]:checked + i {
    27. border-color: blue;
    28. color: blue;
    29. }
    30. /**
    31. * i标签的大小
    32. */
    33. i {
    34. position: absolute;
    35. top: 0;
    36. left: 0;
    37. width: 100%;
    38. height: 100%;
    39. border: 1px solid #ccc;
    40. text-align: center;
    41. line-height: 36px;
    42. }
    43. /**
    44. * 对勾√效果,使用border
    45. * @type {[type]}
    46. */
    47. span:after {
    48. opacity: 1;
    49. content: ‘‘;
    50. position: absolute;
    51. width: 5px;
    52. height: 15px;
    53. background: transparent;
    54. top: 10px;
    55. right: 5px;
    56. border: 2px solid #fff;
    57. border-top: none;
    58. border-left: none;
    59. -webkit-transform: rotate(35deg);
    60. -moz-transform: rotate(35deg);
    61. -o-transform: rotate(35deg);
    62. -ms-transform: rotate(35deg);
    63. transform: rotate(35deg);
    64. }
    65. /**
    66. * 选中状态,span(三角形)样式
    67. * @type {String}
    68. */
    69. input[type="checkbox"]:checked + i + span {
    70. width: 0px;
    71. height: 0px;
    72. border-color: blue transparent;
    73. border-width: 0px 0px 30px 30px;
    74. border-style: solid;
    75. position: absolute;
    76. right: -1px;
    77. top: 10px;
    78. opacity: 1;
    79. }
    80. }
    81. }
    82. </style>
    83. </head>
    84. <body>
    85. <div class="div-checked">
    86. <label>
    87. <input type="checkbox" value="cbEticket">
    88. <i>电子票</i><span></span>
    89. </label>
    90. <label>
    91. <input type="checkbox" checked="" value="cbMeetingRemind">
    92. <i>会议提醒</i><span></span>
    93. </label>
    94. </div>
    95. </body>
    96. </html>
 

css 设置 checkbox复选框控件的对勾√样式

标签:border   absolute   poi   nbsp   inpu   oct   中标   inline   bsp   

原文地址:http://www.cnblogs.com/liusc/p/57c27a929622b8de72155d98888f67cc.html

猜你喜欢

转载自www.cnblogs.com/xiaoshen666/p/10721404.html