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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM