How to get multi select dropdown in Materialize css?

扶醉桌前 提交于 2019-12-23 07:48:05

问题


I am working on a project which uses Materialize css for front end.

Is there any way to get multi select option for dropdown in Materialize css ?

Any piece of info would be helpful.


回答1:


The materialize staff released a version with multiselect:

just add the multiple:

<div class="input-field col s12">
    <select multiple>
        <option value="" disabled selected>Choose your option</option>
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
    </select>
    <label>Materialize Multiple Select</label>
</div>

And then call js:

$(document).ready(function() {
    $('select').material_select();
});

jsfiddle




回答2:


MaterializeCSS's dropdown implementation is not a <select> block. It is just a styled <ul>. Therefore, I don't believe you can take advantage of a multi-select with their implementation. I would use the default <select> block like this:

<select class="browser-default" multiple>
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>

Note: you must add the browser-default class so that MaterializeCSS doesn't render it.




回答3:


Since the top and left css properties of the label are set to ~0.8rem each, you can add a specific rule to the li's:

#topics_dropdown li {
  height: 3rem;
}


来源:https://stackoverflow.com/questions/30207047/how-to-get-multi-select-dropdown-in-materialize-css

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