2016-07-18 13 views
5

入力を一定の幅になるようにスタイル設定しようとしています。私はAngular Material 2を使用していますが、何らかの理由でCSSのスタイルが入力タグに適用されていません。影響を受けるコードと一緒にHere is a working plunker of my issue角度のある材質の入力のカスタムスタイル2

@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() {} 
} 

どのように私は、角資料2で作成されている入力のスタイルを設定することができますか?

答えて

9

あなたは、このよう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; 
} 
+0

このソリューションの効果すべての入力を。 1つの入力または入力のグループに対してのみ行う方法はありますか? – Hayzum

関連する問題