Open a color input with display:none via a label (webkit)

混江龙づ霸主 提交于 2020-01-01 16:58:35

问题


I want to hide an input element and trigger it with an associated label.

Usually that's not a problem. I can simply set display:none on the input like this

input {
  display: none;
}
<input id="upload" type="file" />
<label for="upload">Upload a file</label>

For some reason in Chrome (Firefox works), this technique is not working for a color input - DEMO

input {
  display: none;
}
<input id="colorPick" type="color" />
<label for="colorPick">Pick a color</label>

Is this a webkit bug or is there a logical reason as to why this doesn't work?


回答1:


I guess it is a bug, for chrome(not really sure about other browsers). you can have a workaround for this specific situation: http://jsfiddle.net/z1ta7ou0/4/

instead of using

input {
  display: none;
}

use

input {
   visibility :hidden;
    width:0px;
padding:0;
margin:0;
}

seems like there is only display:none which causes the problem(label not getting associated), otherwise works fine.

I have also opened an issue here, you can track it



来源:https://stackoverflow.com/questions/28189262/open-a-color-input-with-displaynone-via-a-label-webkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!