单选框和上传文件的input的样式美化

红太狼 2024-04-20 09:00 158阅读 0赞
1.效果如下:

在这里插入图片描述

2.HTML代码如下:
  1. <div>
  2. <label class="radio_diy">
  3. <input name="sex" type="radio" checked="checked" /><span class="label"></span>
  4. <br>
  5. </label>
  6. <label class="radio_diy">
  7. <input name="sex" type="radio"/><span class="label"></span>
  8. </label>
  9. </div>
  10. <div class="file-wraps">
  11. <span>上传文件</span>
  12. <input type="file" />
  13. </div>
3.CSS代码如下:
  1. /* 此为单选框样式 */
  2. .radio_diy{
  3. display: block;
  4. position: relative;
  5. height: 30px;
  6. line-height: 30px;
  7. margin-bottom: 15px
  8. }
  9. .label{
  10. display: block;
  11. position: relative;
  12. padding-left:30px;
  13. box-sizing: border-box;
  14. color: #999;
  15. }
  16. .label::after{
  17. content: "";
  18. border:1px solid #999;
  19. width:20px;
  20. height: 20px;
  21. display: block;
  22. position: absolute;
  23. top:50%;
  24. margin-top: -10px;
  25. left: 0px;
  26. border-radius: 50%;
  27. }
  28. .label::before{
  29. content:"";
  30. background: #2971f6;
  31. border-radius: 50%;
  32. display: block;
  33. width: 14px;
  34. height: 14px;
  35. position: absolute;
  36. top:50%;
  37. margin-top: -6px;
  38. left: 4px;
  39. opacity: 0;
  40. }
  41. .radio_diy input{
  42. display: none;
  43. }
  44. .radio_diy input:checked + .label:after{
  45. border-color: #2971f6;
  46. }
  47. .radio_diy input:checked + .label:before{
  48. opacity: 1;
  49. transition: opacity 0.5s ease;
  50. }
  51. .radio_diy input:checked + .label{
  52. color: #2971f6;
  53. transition: color 0.6s ease;
  54. }
  55. /* 此为上传文件样式 */
  56. .file-wraps{
  57. background:#fa8823;
  58. width: 100px;
  59. height: 45px;
  60. line-height: 45px;
  61. position: relative;
  62. color: #fff;
  63. text-align: center;
  64. border-radius: 5px;
  65. }
  66. .file-wraps input{
  67. position: absolute;
  68. top: 0;
  69. left: 0;
  70. bottom: 0;
  71. right: 0;
  72. opacity: 0;
  73. }

发表评论

表情:
评论列表 (有 0 条评论,158人围观)

还没有评论,来说两句吧...

相关阅读

    相关 jQuery /复美化

    对于前端萌新来说,美化表单是个痛苦的事情,通常都是去寻找插件这种逃避的办法,其实这并不是难事。在上篇文章中提到了兄弟元素选择器在表单美化中表现突出,下面的示例源码将体现 基础篇