Is there a way to apply a CSS style on HTML5 datal

2019-01-04 02:30发布

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.

2条回答
甜甜的少女心
2楼-- · 2019-01-04 02:54

try:

input[list]
{
  background: red;
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-04 03:11

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.

查看更多
登录 后发表回答