【问题标题】:Custom styles on inputs with angular material 2带有角度材料 2 的输入的自定义样式
【发布时间】:2016-11-21 10:53:30
【问题描述】:

我正在尝试设置输入的样式,使其具有一定的宽度。我正在使用 Angular Material 2,但由于某种原因,css 中的样式未应用于输入标签。 Here is a working plunker of my issue 以及受影响的代码:

@Component({
  selector: 'my-app',
  template: `
  <div>
    <form>
      <md-input [(ngModel)]="cycleTime" type="number" name="email">
        <span md-prefix>Cycle Time:</span>
        <span md-suffix>&nbsp;minutes</span>
      </md-input>
    </form>
  </div>
  `,
  styles:[`
      input {
        width: 50px;
        text-align: right;
      }
    `],
  directives: [MdButton, MdInput]
})
export class AppComponent { 
  cycleTime = 1

  constructor() {}
}

如何设置由 Angular Material 2 创建的输入的样式?

【问题讨论】:

标签: angular angular2-forms angular-material2


【解决方案1】:

您可以尝试像这样覆盖MdInput 组件的样式:

:host input.md-input-element {
  width: 50px;
  text-align: right;
}

Plunker example

或者这样:

/deep/ input {
  width: 50px !important;
  text-align: right;
}

:host-context .md-input-infix input {
  width: 50px;
  text-align: right;
}

【讨论】:

  • 此解决方案影响所有输入。有没有办法只针对一个输入或一组输入?
  • @hayzum ::ng-deep .myinput {}
猜你喜欢
  • 2020-04-26
  • 2015-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-03
  • 2021-06-12
  • 2021-07-25
  • 2019-08-13
相关资源
最近更新 更多