text-align in md-grid-tile (Angular Material) doesn't work

后端 未结 5 624
野趣味
野趣味 2021-02-04 01:19

text-align in Angular Material doesn\'t work.

{{video         


        
相关标签:
5条回答
  • 2021-02-04 01:45

    Target div elements inside mat-grid-tile with a width of 100 percent.

    my.component.scss

    mat-grid-tile div {
      width: 100%;
      text-align: left;
    }
    

    my.component.html

    <mat-grid-list cols="12">
      <mat-grid-tile colspan="4">
        <img [src]="hero.avatarUrl" i18n-alt alt="Hero avatar" />
      </mat-grid-tile>
    
      <mat-grid-tile colspan="8">
        <div>
          <h1>
            {{ hero.firstName }}
            {{ hero.lastName }}
          </h1>
        </div>
      </mat-grid-tile>
    </mat-grid-list>
    
    
    0 讨论(0)
  • 2021-02-04 01:51

    You could simply put a span or div tag around your text inside md-grid-tile:

    <md-grid-tile>
        <div class="text-inside-grid">{{ video.title }}</div>
    </md-grid-tile>
    

    and then style it:

    .text-inside-grid {
      position: absolute;
      left: 5px;
    }
    
    0 讨论(0)
  • 2021-02-04 01:53

    Another alternative with flex-layout (and using the latest 'mat-' prefix):

    <mat-grid-tile>
        <div fxFlex fxLayoutAlign="start center">{{ video.title }}</div>
    </mat-grid-tile>
    
    0 讨论(0)
  • 2021-02-04 02:04

    for those who have problems getting this example to work in angular2 you might need to add the ::ng-deep selector to the css for the figure

    <md-grid-tile class="video-title">
        {{ video.title }}
    </md-grid-tile>
    

    css

     .video-title > ::ng-deep figure {
         justify-content: flex-start !important;
     }
    

    *updated /deep/ to ::ng-deep because /deep/ was deprecated

    0 讨论(0)
  • 2021-02-04 02:07

    I did it!

    <md-grid-tile>{{video.created}}</md-grid-tile>
    <md-grid-tile>{{video.code</md-grid-tile>
    
    <md-grid-tile style="text-align: left;" class="video-title">
        {{ video.title }}
    </md-grid-tile>
    
    <md-grid-tile>{{video.playtime}}</md-grid-tile>
    

    css

    .video-title > figure {
        justify-content: flex-start !important;
    }
    
    0 讨论(0)
提交回复
热议问题