移动端关于select最佳兼容性解决方案(css)

让人头疼的select框在移动设备端的兼容性问题

原文链接:http://blog.csdn.net/yuu2lee4/article/details/49357261

支持浏览器

 
  1. iOS 4/5/6/7/8 - looks good, iOS3 even works fine but isn't quite as pretty
  2. Android 2.2/2.3 (Browser) - looks good
  3. Android 4.0/4.1/4.2 (Browser) - looks good
  4. Android 4.0/4.1/4.2/4.3/4.4 (Chrome) - looks good
  5. WP8 - looks good
  6. Kindle Fire 2/HD - looks good
  7. IE 10/11 - looks good
  8. Safari 5 - looks good
  9. Chrome 22-35 - looks good
  10. Opera 15-22 - looks good

html代码

 
  1. <div class="button custom-select">
  2. <select name="" id="">
  3. <option value="选择1">选择1</option>
  4. <option value="选择2">选择2</option>
  5. <option value="选择3">选择3</option>
  6. <option value="选择4">选择4</option>
  7. </select>
  8. </div>

css代码

 
  1. .button {
  2. border: 1px solid #bbb;
  3. border-radius: 1px;
  4. box-shadow: 0 1px 0 1px rgba(0,0,0,.04);
  5. width: 300px;
  6. background: #f3f3f3;
  7. background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%);
  8. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5));
  9. background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%);
  10. background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%);
  11. background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%);
  12. background: linear-gradient(to bottom, #ffffff 0%,#e5e5e5 100%);
  13. }
  14. /* -------------- */
  15. /* custom-select */
  16. /* -------------- */
  17. .custom-select {
  18. position: relative;
  19. }
  20. .custom-select select {
  21. width:100%;
  22. margin:0;
  23. background:none;
  24. border: 1px solid transparent;
  25. outline: none;
  26. /* Prefixed box-sizing rules necessary for older browsers */
  27. -webkit-box-sizing: border-box;
  28. -moz-box-sizing: border-box;
  29. box-sizing: border-box;
  30. /* Remove select styling */
  31. appearance: none;
  32. -webkit-appearance: none;
  33. /* Font size must the 16px or larger to prevent iOS page zoom on focus */
  34. /* General select styles: change as needed */
  35. font-family: helvetica, sans-serif;
  36. font-weight: bold;
  37. color: #444;
  38. padding: .6em 1.9em .5em .8em;
  39. line-height:1.3;
  40. }
  41. .custom-select::after {
  42. content: "";
  43. position: absolute;
  44. width: 0px;
  45. height: 0px;
  46. top: 50%;
  47. right: 8px;
  48. margin-top:-4px;
  49. border:8px solid #929497;
  50. border-width: 8px 5px 8px;
  51. border-color: #929497 transparent transparent transparent;
  52. z-index: 2;
  53. pointer-events:none;
  54. }
  55. /* Hover style */
  56. .custom-select:hover {
  57. border:1px solid #888;
  58. }
  59. /* Focus style */
  60. .custom-select select:focus {
  61. outline:none;
  62. box-shadow: 0 0 1px 3px rgba(180,222,250, 1);
  63. background-color:transparent;
  64. color: #222;
  65. border:1px solid #aaa;
  66. }
  67. /* Set options to normal weight */
  68. .custom-select option {
  69. font-weight:normal;
  70. }
  71. x:-o-prefocus, .custom-select::after {
  72. display:none;
  73. }
  74. @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  75. .custom-select select::-ms-expand {
  76. display: none;
  77. }
  78. .custom-select select:focus::-ms-value {
  79. background: transparent;
  80. color: #222;
  81. }
  82. }
  83. @-moz-document url-prefix() {
  84. .custom-select {
  85. overflow: hidden;
  86. }
  87. .custom-select select {
  88. width: 120%;
  89. width: -moz-calc(100% + 3em);
  90. width: calc(100% + em);
  91. }
  92. }
  93. .custom-select select:-moz-focusring {
  94. color: transparent;
  95. text-shadow: 0 0 0 #000;
  96. }

可以借鉴上面的css部分,根据自己的需求稍作修改
(不过,在我的页面里,这种方法,对移动端的QQ浏览器还是不兼容,正在找办法解决中.)
这里是我的学习笔记--大贝
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值