我正在尝试设置输入的样式,使其具有一定的宽度。我使用的是 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 - 使用 Angular Material 2 输入的自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38443373/