2016-07-18 65 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

該解決方案影響的所有輸入。有沒有辦法只做一個輸入或一組輸入? – Hayzum