Is there a way to apply a CSS style on HTML5 datalist options?

心已入冬 提交于 2019-11-26 02:24:11

问题


I would like to modify the way that the list of the different options of my datalist are displayed. Is it possible to apply on it some CSS properties ?

<input list=\"languages\" id=\"language_id\">
<datalist id=\"languages\">
      <option value=\"html\">HTML</option>
      <option value=\"java\">Java</option>
      <option value=\"perl\">Perl</option>
      <option value=\"php\">PHP</option>
      <option value=\"ruby-on-rails\">Ruby on Rails</option>
</datalist>

I tried

option {
    background: red;
}

but it does not seem to work.


回答1:


Like select elements, the datalist element has very little flexibility in styling. You cannot style any of the suggested terms if that's what your question was asking.

Browsers define their own styles for these elements.




回答2:


try:

input[list]
{
  background: red;
}


来源:https://stackoverflow.com/questions/13693482/is-there-a-way-to-apply-a-css-style-on-html5-datalist-options

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