Angular 5 Mat-grid list responsive

后端 未结 6 1758
灰色年华
灰色年华 2021-01-30 03:08

i created grid list with column 6 and i want to be grid title take 100% width on small screen devices. Now it creates 6 column on small screens as well

Expected: One gri

6条回答
  •  轮回少年
    2021-01-30 03:48

    You have to set the cols attribute of the mat-grid-list dynamically depending on the screen width. You'd have to decide on which width breakpoint will the mat-grid-list render the 1-column version.

    HTML:

    
      1
      2
      3
      4
      5
      6
    
    

    TS:

    ngOnInit() {
        this.breakpoint = (window.innerWidth <= 400) ? 1 : 6;
    }
    
    onResize(event) {
      this.breakpoint = (event.target.innerWidth <= 400) ? 1 : 6;
    }
    

    Stackblitz demo here

    Hope this helps!

提交回复
热议问题