KetZoomer
KetZoomer

Reputation: 2915

MaterializeCSS Select Background Color

I tried the background color of the MaterializeCSS select. I attempted to use this question, but it did not work Change select box option background color as it was for regular HTML (no Materialize).

How could I do this?

Upvotes: 2

Views: 563

Answers (1)

radrex
radrex

Reputation: 329

It has to do with Materialize's selectors. The below code worked for me:

<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<div class="input-field col s12">
    <select class="select1">
        <option value="1" selected>Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
    </select>
    <label>Materialize Select</label>
</div>
<style>
  input.select-dropdown {
      background: #1A1B1C !important;
      color: #26a69a;
  }
  ul.dropdown-content.select-dropdown li span {
      background: #1A1B1C; 
  }
</style>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        var elems = document.querySelectorAll('select');
        var instances = M.FormSelect.init(elems);
    });
</script>

Upvotes: 2

Related Questions