Search code examples
htmlcssmaterialize

Q: Materialize css formatting form inputs


I am trying to change the border and label color of the form input in materialize css. I followed the documentation but only the first instance of the .input-field div is being changed, the rest are still using the default style.

Codepen

HTML

<div class="input-field">
  <input id="account_name" type="text" class="validate">
  <label for="account_name">Account Name</label>
</div>

<div class="input-field">
  <input id="email" type="email" class="validate">
  <label for="email">Email</label>
</div>

<div class="input-field">
  <input id="password" type="password" class="validate">
  <label for="password">Password</label>
</div>

CSS

/* label color */
.input-field label {
    color: #000;
}
/* label focus color */
.input-field input[type=text]:focus + label {
    color: purple !important;
}
/* label underline focus color */
.input-field input[type=text]:focus {
    border-bottom: 1px solid purple !important;
    box-shadow: 0 1px 0 0 purple !important;
}
/* valid color */
.input-field input[type=text].valid {
    border-bottom: 1px solid purple !important;
    box-shadow: 0 1px 0 0 purple !important;
}
/* invalid color */
.input-field input[type=text].invalid {
    border-bottom: 1px solid #000;
    box-shadow: 0 1px 0 0 #000;
}
/* icon prefix focus color */
.input-field .prefix.active {
    color: #000;
}

EDIT: typo on title


Solution

  • Your CSS is pseudo-selecting inputs with [type=text]. Don't you want to get the ones with type="email" and type="password" too?