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

5

33

text-align in Angular Material <md-grid-tile> doesn't work.

<md-grid-tile>{{video.created}}</md-grid-tile>
<md-grid-tile>{{video.code</md-grid-tile>

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

<md-grid-tile>{{video.playtime}}</md-grid-tile>

I want to align text like this:

enter image description here

but text-align in <md-grid-tile> didn't work :(

How can I do it?

Swipple answered 23/5, 2016 at 8:41 Comment(2)
Try <md-grid-tile style="text-align: left !important;">Jocose
I tried <md-grid-tile style="text-align: left !important;"> but it also didn't work, sorrySwipple
D
57

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;
}
Decolorant answered 21/10, 2016 at 15:8 Comment(3)
It works perfect for <mat-grid-tile> too (angular 5 material: <mat-grid-list>)Vicious
why it is position: absolute instead of position: relative ?Beckiebeckley
I couldn't remember how md-grid-tile works but I think that's because you'd want to position your text relative to its parent (md-grid-tile).Decolorant
A
14

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

Anemia answered 8/6, 2017 at 9:13 Comment(0)
C
4

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>
Candracandy answered 11/10, 2018 at 22:30 Comment(0)
S
1

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;
}
Swipple answered 24/5, 2016 at 4:45 Comment(0)
H
1

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>

Hindward answered 28/8, 2020 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.