简体   繁体   English

用于输入的角材料 2 颜色

[英]Angular material 2 colour for input

Angular material 2 colour for input用于输入的角材料 2 颜色

<md-input-container >
  <input type="password" md-input placeholder="password">

</md-input-container>

i want the colour to be changed on the click, How can I do that?我想在点击时更改颜色,我该怎么做?

Keep in mind that you don't want to go crazy with Material colors, they limit and assign them to various UI elements and states for a reason.请记住,您不想为 Material 颜色发疯,它们出于某种原因限制并将它们分配给各种 UI 元素和状态。

With that said ...照这样说 ...

If you are asking how you change the color when the item has focus you can use the color="" attribute and set it to 'primary' 'default', 'accent', or 'warn' though this will violate some material principles since you are potentially signalling an incorrect state to your user when you do so.如果您询问当项目具有焦点时如何更改颜色,您可以使用 color="" 属性并将其设置为 'primary'、'default'、'accent' 或 'warn',尽管这会违反一些实质性原则,因为当您这样做时,您可能会向您的用户发出不正确的状态信号。

<md-input-container color='accent'>
  <input type="password" md-input placeholder="password">
</md-input-container>

Here's a plunker with the google company name set to 'accent'这是一个 google 公司名称设置为“accent”的 plunker

If you just don't like the default colors then I suggest you could create your own theme如果您只是不喜欢默认颜色,那么我建议您可以创建自己的主题

If you really want to go crazy you can overide the SASS input mixins for the input class如果你真的想发疯,你可以覆盖输入类的 SASS 输入混合

https://github.com/angular/material2/blob/0666207527299758293a9587a5b79212167a9a70/src/lib/input/_input-theme.scss https://github.com/angular/material2/blob/0666207527299758293a9587a5b79212167a9a70/src/lib/input/_input-theme.scss

I don't suggest that though if you want to stick to the material design guidelines如果你想坚持材料设计指南,我不建议这样做

If you are looking to set states that's a different question如果你想设置状态,那是一个不同的问题

https://material.angular.io/guide/theming https://material.angular.io/guide/theming

style.css样式文件

.mat-dark {
      @include angular-material-theme($dark-app-theme);
      input {
        color: white;
      }
    }

<div class="mat-dark">
    <md-input-container>
       <input type="password" md-input placeholder="password">
    </md-input-container>
</div>
.mat-focused .mat-form-field-label {
    color: #5cb53f !important;
}

.mat-form-field-ripple {
    background-color: #5cb53f !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM