html – 自定义选择下拉箭头不可点击

前端之家收集整理的这篇文章主要介绍了html – 自定义选择下拉箭头不可点击前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用以下代码自定义我的选择下拉箭头:

HTML:

  1. <span class="selectWrapper">
  2. <select id="rowselect" class="pageinfoselect input-mini">
  3. <option>...</option>
  4. </select>
  5. </span>

CSS:

  1. span.selectWrapper {
  2. position: relative;
  3. display: inline-block;
  4. width:65px;
  5. }
  6.  
  7. span.selectWrapper select {
  8. display: inline-block;
  9. padding: 4px 3px 3px 5px;
  10. margin: 0;
  11. font: inherit;
  12. outline:none; /* remove focus ring from Webkit */
  13. line-height: 1.2;
  14. background: #f5f5f5;
  15. height:30px;
  16. color:#666666;
  17. border:1px solid #dddddd;
  18. }
  19.  
  20.  
  21.  
  22.  
  23. /* Select arrow styling */
  24. span.selectWrapper:after {
  25. content: url("../images/arrow_down.png");
  26. position: absolute;
  27. top: 0;
  28. right: 0;
  29. bottom: 0;
  30. line-height: 30px;
  31. padding: 0 7px;
  32. background: #f5f5f5;
  33. color: white;
  34. border:1px solid #dddddd;
  35. border-left:0px;
  36. }

这很好,并取代了默认的下拉箭头,但问题是箭头图像不可点击.如果我点击它打开的选择框,但我也希望它在我点击箭头图像时打开

解决方法

添加以下规则
  1. pointer-events:none;

编辑:

应该注意的是IE还不支持这个属性(尽管根据caniuse – 它将在IE11中得到支持)

但是,如果您仍然想要这种方法,您可以使用Modernizer或条件注释(对于IE< 10)和this css hack(对于IE10)使IE恢复为标准内置箭头.

  1. /*target Internet Explorer 9 and Internet Explorer 10:*/
  2. @media screen and (min-width:0\0) {
  3. span.selectWrapper:after
  4. {
  5. display:none;
  6. }
  7. }

然而,有一个解决方法(也是一个不同的解决方案),我在my answer here提到 – 其中也包含this FIDDLE

猜你在找的HTML相关文章