angular material 2 输入的自定义样式
Custom styles on inputs with angular material 2
我正在尝试设置输入样式以使其具有特定宽度。我正在使用 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> 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 创建的输入的样式?
您可以像这样尝试覆盖 MdInput
组件的样式:
:host input.md-input-element {
width: 50px;
text-align: right;
}
或者这样:
/deep/ input {
width: 50px !important;
text-align: right;
}
:host-context .md-input-infix input {
width: 50px;
text-align: right;
}
我正在尝试设置输入样式以使其具有特定宽度。我正在使用 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> 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 创建的输入的样式?
您可以像这样尝试覆盖 MdInput
组件的样式:
:host input.md-input-element {
width: 50px;
text-align: right;
}
或者这样:
/deep/ input {
width: 50px !important;
text-align: right;
}
:host-context .md-input-infix input {
width: 50px;
text-align: right;
}