[关闭]
@sammffl 2016-06-26T05:11:08.000000Z 字数 1031 阅读 1211

重写单选复选按钮

小技巧


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>属性选择器</title>
  6. <link href="style.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body>
  9. <form action="#">
  10. <div class="wrapper">
  11. <div class="box">
  12. <input type="radio" checked="checked" id="boy" name="1" /><span></span>
  13. </div>
  14. <label for="boy"></label>
  15. </div>
  16. <div class="wrapper">
  17. <div class="box">
  18. <input type="radio" id="girl" name="1" /><span></span>
  19. </div>
  20. <label for="girl"></label>
  21. </div>
  22. </form>
  23. </body>
  24. </html>
  1. form {
  2. border: 1px solid #ccc;
  3. padding: 20px;
  4. width: 300px;
  5. margin: 30px auto;
  6. }
  7. .wrapper {
  8. margin-bottom: 10px;
  9. }
  10. .box {
  11. display: inline-block;
  12. width: 30px;
  13. height: 30px;
  14. margin-right: 10px;
  15. position: relative;
  16. background: orange;
  17. vertical-align: middle;
  18. border-radius: 100%;
  19. }
  20. .box input {
  21. opacity: 0;
  22. position: absolute;
  23. top:0;
  24. left:0;
  25. width: 100%;
  26. height:100%;
  27. z-index:100;/*使input按钮在span的上一层,不加点击区域会出现不灵敏*/
  28. }
  29. .box span {
  30. display: block;
  31. width: 10px;
  32. height: 10px;
  33. border-radius: 100%;
  34. position: absolute;
  35. background: #fff;
  36. top: 50%;
  37. left:50%;
  38. margin: -5px 0 0 -5px;
  39. z-index:1;
  40. }
  41. input[type="radio"] + span {
  42. opacity: 0;
  43. }
  44. input[type="radio"]:checked + span {
  45. opacity: 1;
  46. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注