angular material: vertically arranging contents in a mat-grid-tile

前端 未结 2 2069
轻奢々
轻奢々 2021-01-04 21:32

I am using angular material and have a grid list component with two tiles. the problem is the contents are getting arranged left to right rather top to bottom.



        
相关标签:
2条回答
  • 2021-01-04 22:03

    try below one, you have set colspan so that it will occupy full width of the div

    <mat-grid-list cols="3" style="padding:10px">
    <mat-grid-tile md-colspan="6" colspan="6" class="mi-tile-contents-top">
      <h2 class="mi-text-header">Title</h2>
      <div>some sort of text in between</div>
      <button mat-raised-button class="mi-button">Learn More</button>
     </mat-grid-tile>
    <mat-grid-tile md-colspan="6" colspan="6" ><img src="../assets/images/cg_app.png" width="100%"/></mat-grid-tile>
    </mat-grid-list>
    
    0 讨论(0)
  • 2021-01-04 22:08

    The reason it's horizontal is because the Material lib is wrapping your tags located inside mat-grid-tile in a flex styled element that has a row flex-direction by default.

    If I get it right, the code below should do want you want. When using grid-list elements, the order has an importance

    <mat-grid-list cols="3" style="padding:10px">
        <mat-grid-tile colspan="1" rowspan="1">
            <h2>Title</h2>
        </mat-grid-tile>
        <mat-grid-tile colspan="2" rowspan="3">
            <img src="../assets/images/cg_app.png" width="100%"/>
        </mat-grid-tile>
        <mat-grid-tile colspan="1" rowspan="1">
          <div>some sort of text in between</div>
        </mat-grid-tile>
        <mat-grid-tile colspan="1" rowspan="1">
          <button mat-raised-button class="mi-button">Learn More</button>
        </mat-grid-tile>
    </mat-grid-list>
    

    You could also wrap the content of your mat-grid-tile in a div:

    <mat-grid-list cols="3" style="padding:10px">
        <mat-grid-tile colspan="2" >
            <div>
                <h2>Title</h2>
                <div>some sort of text in between</div>
                <button mat-raised-button class="mi-button">Learn More</button>
            </div>
        </mat-grid-tile>
        <mat-grid-tile colspan="1">
            <img src="../assets/images/cg_app.png" width="100%"/>
        </mat-grid-tile>
    </mat-grid-list>
    
    0 讨论(0)
提交回复
热议问题