Material flex layout - one grid overlaps over other when it is small screen











up vote
-1
down vote

favorite












Created this stackblitz.



When it is in desktop and full screen the output loks good, but when the browser windows size is small, then one grid is overlapping over the other grid.



I want the grids to be 100% height so I can put my contents inside them and when the screen is small one grid should take the entire screen, i.e not more or less then the entire screen height minus the top navbar.



Not sure, but may be because of below css code. But if I remove these css code, I am not getting full screen grids. that means it looks like below



CSS:



.mat-drawer-content {
position: absolute !important;
}

.mat-grid-list {
height: 100%;
}

.mat-grid-list {
position: initial !important;
}


ulenter image description hereenter image description here










share|improve this question




























    up vote
    -1
    down vote

    favorite












    Created this stackblitz.



    When it is in desktop and full screen the output loks good, but when the browser windows size is small, then one grid is overlapping over the other grid.



    I want the grids to be 100% height so I can put my contents inside them and when the screen is small one grid should take the entire screen, i.e not more or less then the entire screen height minus the top navbar.



    Not sure, but may be because of below css code. But if I remove these css code, I am not getting full screen grids. that means it looks like below



    CSS:



    .mat-drawer-content {
    position: absolute !important;
    }

    .mat-grid-list {
    height: 100%;
    }

    .mat-grid-list {
    position: initial !important;
    }


    ulenter image description hereenter image description here










    share|improve this question


























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      Created this stackblitz.



      When it is in desktop and full screen the output loks good, but when the browser windows size is small, then one grid is overlapping over the other grid.



      I want the grids to be 100% height so I can put my contents inside them and when the screen is small one grid should take the entire screen, i.e not more or less then the entire screen height minus the top navbar.



      Not sure, but may be because of below css code. But if I remove these css code, I am not getting full screen grids. that means it looks like below



      CSS:



      .mat-drawer-content {
      position: absolute !important;
      }

      .mat-grid-list {
      height: 100%;
      }

      .mat-grid-list {
      position: initial !important;
      }


      ulenter image description hereenter image description here










      share|improve this question















      Created this stackblitz.



      When it is in desktop and full screen the output loks good, but when the browser windows size is small, then one grid is overlapping over the other grid.



      I want the grids to be 100% height so I can put my contents inside them and when the screen is small one grid should take the entire screen, i.e not more or less then the entire screen height minus the top navbar.



      Not sure, but may be because of below css code. But if I remove these css code, I am not getting full screen grids. that means it looks like below



      CSS:



      .mat-drawer-content {
      position: absolute !important;
      }

      .mat-grid-list {
      height: 100%;
      }

      .mat-grid-list {
      position: initial !important;
      }


      ulenter image description hereenter image description here







      css angular css3 flexbox angular-material






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago









      Michael_B

      140k43223331




      140k43223331










      asked 4 hours ago









      SK.

      248215




      248215
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          IME it is very tricky - maybe impossible - to get around MatGrid's own layout mechanism and force it to behave a certain way using CSS or flex-layout, because the component is designed to be dynamically layed out using calculations. You've done it the right way with cols but you need to apply the same idea to rowHeight. Something like:



          <mat-grid-list [cols]="breakpoint" [rowHeight]="ratio" (window:resize)="onResize($event)">

          ...

          breakpoint: number;
          ratio: string;
          constructor(private el: ElementRef) { }

          ngOnInit() {
          this.resize(window.innerWidth);
          }

          onResize(event) {
          this.resize(event.target.innerWidth);
          }

          resize(width: number) {
          if (width <= 400) {
          this.breakpoint = 1;
          this.ratio = this.el.nativeElement.offsetWidth + ':' + this.el.nativeElement.offsetHeight / 4;
          } else {
          this.breakpoint = 4;
          this.ratio = this.el.nativeElement.offsetWidth / 4 + ':' + this.el.nativeElement.offsetHeight;
          }
          }


          Note that you will also need to apply some sort of fixed height to the grid - perhaps via the parent container of the grid (in your case demo-component) and cause the grid to take the height of it's parent:



          :host {
          height: 300px !important;
          align-self: stretch;
          flex: 1 0 100%;
          display: flex;
          justify-content: stretch;
          align-items: stretch;
          }
          .mat-grid-list {
          flex: 1 1 100%;
          }


          This isn't completely perfect, but it's much better. Here it is on StackBlitz.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400783%2fmaterial-flex-layout-one-grid-overlaps-over-other-when-it-is-small-screen%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            IME it is very tricky - maybe impossible - to get around MatGrid's own layout mechanism and force it to behave a certain way using CSS or flex-layout, because the component is designed to be dynamically layed out using calculations. You've done it the right way with cols but you need to apply the same idea to rowHeight. Something like:



            <mat-grid-list [cols]="breakpoint" [rowHeight]="ratio" (window:resize)="onResize($event)">

            ...

            breakpoint: number;
            ratio: string;
            constructor(private el: ElementRef) { }

            ngOnInit() {
            this.resize(window.innerWidth);
            }

            onResize(event) {
            this.resize(event.target.innerWidth);
            }

            resize(width: number) {
            if (width <= 400) {
            this.breakpoint = 1;
            this.ratio = this.el.nativeElement.offsetWidth + ':' + this.el.nativeElement.offsetHeight / 4;
            } else {
            this.breakpoint = 4;
            this.ratio = this.el.nativeElement.offsetWidth / 4 + ':' + this.el.nativeElement.offsetHeight;
            }
            }


            Note that you will also need to apply some sort of fixed height to the grid - perhaps via the parent container of the grid (in your case demo-component) and cause the grid to take the height of it's parent:



            :host {
            height: 300px !important;
            align-self: stretch;
            flex: 1 0 100%;
            display: flex;
            justify-content: stretch;
            align-items: stretch;
            }
            .mat-grid-list {
            flex: 1 1 100%;
            }


            This isn't completely perfect, but it's much better. Here it is on StackBlitz.






            share|improve this answer

























              up vote
              0
              down vote













              IME it is very tricky - maybe impossible - to get around MatGrid's own layout mechanism and force it to behave a certain way using CSS or flex-layout, because the component is designed to be dynamically layed out using calculations. You've done it the right way with cols but you need to apply the same idea to rowHeight. Something like:



              <mat-grid-list [cols]="breakpoint" [rowHeight]="ratio" (window:resize)="onResize($event)">

              ...

              breakpoint: number;
              ratio: string;
              constructor(private el: ElementRef) { }

              ngOnInit() {
              this.resize(window.innerWidth);
              }

              onResize(event) {
              this.resize(event.target.innerWidth);
              }

              resize(width: number) {
              if (width <= 400) {
              this.breakpoint = 1;
              this.ratio = this.el.nativeElement.offsetWidth + ':' + this.el.nativeElement.offsetHeight / 4;
              } else {
              this.breakpoint = 4;
              this.ratio = this.el.nativeElement.offsetWidth / 4 + ':' + this.el.nativeElement.offsetHeight;
              }
              }


              Note that you will also need to apply some sort of fixed height to the grid - perhaps via the parent container of the grid (in your case demo-component) and cause the grid to take the height of it's parent:



              :host {
              height: 300px !important;
              align-self: stretch;
              flex: 1 0 100%;
              display: flex;
              justify-content: stretch;
              align-items: stretch;
              }
              .mat-grid-list {
              flex: 1 1 100%;
              }


              This isn't completely perfect, but it's much better. Here it is on StackBlitz.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                IME it is very tricky - maybe impossible - to get around MatGrid's own layout mechanism and force it to behave a certain way using CSS or flex-layout, because the component is designed to be dynamically layed out using calculations. You've done it the right way with cols but you need to apply the same idea to rowHeight. Something like:



                <mat-grid-list [cols]="breakpoint" [rowHeight]="ratio" (window:resize)="onResize($event)">

                ...

                breakpoint: number;
                ratio: string;
                constructor(private el: ElementRef) { }

                ngOnInit() {
                this.resize(window.innerWidth);
                }

                onResize(event) {
                this.resize(event.target.innerWidth);
                }

                resize(width: number) {
                if (width <= 400) {
                this.breakpoint = 1;
                this.ratio = this.el.nativeElement.offsetWidth + ':' + this.el.nativeElement.offsetHeight / 4;
                } else {
                this.breakpoint = 4;
                this.ratio = this.el.nativeElement.offsetWidth / 4 + ':' + this.el.nativeElement.offsetHeight;
                }
                }


                Note that you will also need to apply some sort of fixed height to the grid - perhaps via the parent container of the grid (in your case demo-component) and cause the grid to take the height of it's parent:



                :host {
                height: 300px !important;
                align-self: stretch;
                flex: 1 0 100%;
                display: flex;
                justify-content: stretch;
                align-items: stretch;
                }
                .mat-grid-list {
                flex: 1 1 100%;
                }


                This isn't completely perfect, but it's much better. Here it is on StackBlitz.






                share|improve this answer












                IME it is very tricky - maybe impossible - to get around MatGrid's own layout mechanism and force it to behave a certain way using CSS or flex-layout, because the component is designed to be dynamically layed out using calculations. You've done it the right way with cols but you need to apply the same idea to rowHeight. Something like:



                <mat-grid-list [cols]="breakpoint" [rowHeight]="ratio" (window:resize)="onResize($event)">

                ...

                breakpoint: number;
                ratio: string;
                constructor(private el: ElementRef) { }

                ngOnInit() {
                this.resize(window.innerWidth);
                }

                onResize(event) {
                this.resize(event.target.innerWidth);
                }

                resize(width: number) {
                if (width <= 400) {
                this.breakpoint = 1;
                this.ratio = this.el.nativeElement.offsetWidth + ':' + this.el.nativeElement.offsetHeight / 4;
                } else {
                this.breakpoint = 4;
                this.ratio = this.el.nativeElement.offsetWidth / 4 + ':' + this.el.nativeElement.offsetHeight;
                }
                }


                Note that you will also need to apply some sort of fixed height to the grid - perhaps via the parent container of the grid (in your case demo-component) and cause the grid to take the height of it's parent:



                :host {
                height: 300px !important;
                align-self: stretch;
                flex: 1 0 100%;
                display: flex;
                justify-content: stretch;
                align-items: stretch;
                }
                .mat-grid-list {
                flex: 1 1 100%;
                }


                This isn't completely perfect, but it's much better. Here it is on StackBlitz.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                G. Tranter

                3,4861220




                3,4861220






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400783%2fmaterial-flex-layout-one-grid-overlaps-over-other-when-it-is-small-screen%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sphinx de Gizeh

                    Dijon

                    Langue