2017-09-01 42 views
1

所以這個:造型材料網格列表項

<md-grid-list cols="5" rowHeight="20px"> 
     <md-grid-tile 
      *ngFor="let carBrand of carBrands" 
      colspan= 1 
      rowspan= 1> 
     <md-checkbox>{{ carBrand}}</md-checkbox> 
     </md-grid-tile> 
    </md-grid-list> 

產生我的名單,但在所有的cols項目爲中心。我在開發工具中看到,如果我將justify-content: center更改爲justify-content: left,它可能運行良好,但在我的代碼中無法實現相同的效果。

如何正確樣式這些?

+0

請告訴我目標是什麼? – onetwo12

+0

來對齊項目 - 向左或向右。現在他們是中心 –

回答

0

設置View Encapsulation爲None您的組件上:

@Component({ 
    templateUrl: './my.component.html' , 
    styleUrls: ['./my.component.css'], 
    encapsulation: ViewEncapsulation.None, 
}) 

然後在你的組件的CSS,你可以做你的開發者工具嘗試什麼,重寫風格justify-content: left

查看封裝=無意味着Angular不會查看封裝。 Angular將CSS添加到全局樣式中。前面討論的規則,隔離和保護範圍不適用。這個 與將組件的樣式粘貼到HTML中的基本相同。

+0

謝謝,現在我可以將它們左對齊,但只有當我使用'!important'時。也許我錯過了什麼..?我導入了ViewEncapsulation並添加了'.mat-grid-tile .mat-figure justify-content:left!important; }'到component.css –

+0

不,你不會錯過任何東西,應該這樣做 –