Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use html datalist with bootstrap?

Given

<input list="browsers" name="browser">
<datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

How to apply bootstrap css to this? I would except just to add class="form-control" and it would be layouted in the same fasion as a select element? But that did not work. Is this tag not supported?

like image 507
ajthinking Avatar asked Feb 10 '18 16:02

ajthinking


People also ask

How the Datalist tag can be used in HTML?

The <datalist> tag is used to provide an "autocomplete" feature for <input> elements. Users will see a drop-down list of pre-defined options as they input data.

Is Datalist supported by all browsers?

Unfortunately, Internet Explorer and Chrome are the only browsers to support datalists on range inputs at this time.

Is Datalist tag in HTML5?

The datalist tag is introduced in HTML5. The <datalist> tag should be used with an <input< element that contains a "list" attribute. The value of "list" attribute is linked with the datalist id.

How do I make a small text box in bootstrap?

Use the . input-sm class to set small input field in Bootstrap.


1 Answers

I cannot confirm, that bootstrap 4 does generally not work with the <input>/<datalist> element. Basically you only apply the select field bootstrap classes to the input field, which then gets the look of a select/dropdown with input functionality, e.g.:

<input list="encodings" value="" class="col-sm-6 custom-select custom-select-sm">
<datalist id="encodings">
    <option value="ISO-8859-1">ISO-8859-1</option>
    <option value="cp1252">ANSI</option>
    <option value="utf8">UTF-8</option>
</datalist>

Looks like that on recent Firefox:

enter image description here

like image 134
anarchist912 Avatar answered Nov 04 '22 14:11

anarchist912