Sample Grid And Flex Layouts For Components

Responsive Web Design

This page continues the awesome the lesson;
https://1linelayouts.glitch.me/

And continues Mozilla's formal documentation;
Mozilla - Basic_Concepts_of_Grid_Layout

Further Reading
- place-items:center; Mozilla - place-items:center;
- Grid Layout; Mozilla - Grid Layout Concepts
.grid-3col-centered { display: grid; grid-template-columns: auto auto auto; place-items:center; } /* use a grid layout 3 col - auto distribute col_width center vertically and horizontally */
child 1
:-] 2
child 3
child 4
❤ 5
child 6
.super-centered { display: grid; place-items:center; } /* use a grid layout center vertically and horizontally grid-template-columns: auto; // applied by default */
child 1
.flex-with-strechy-children { display:flex; flex-wrap: wrap; justify-content: center; } .flex-with-strechy-children div { /* flex-grow flex-shrink flex-basis */ flex: 1 1 110px; margin: 5px; }
child 1
child 2
child 3
.flex-center-children { display:flex; flex-wrap: wrap; justify-content: space-around; align-items:center; } .flex-center-children div { /* flex-grow flex-shrink flex-basis */ flex: 0 1 110px; margin: 5px; background-color: navy; padding: 5px; border-radius: 0.5rem; /* idiom: center child content */ display:grid; place-items: center; }
child 1
child 2
child 3
Further reading about grid & repeat - https://developer.mozilla.org/en-US/docs/Web/CSS/repeat
.grid-repeat { display: grid; grid-gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } /* a. repeat apply parameters to all children b. auto-fit - CSS engine computes the largest number of grid tracks such that the container contains grid tracks without overflow; -- also then the CSS engine collapses any emtpy grid track. Each grid track contains exactly one child-element. c. CSS engine computes computes minimum child width as 150px d. compute max child width as 1fr Note: (1fr == 1 flex-factor) - Each <flex>-sized track takes a share of the remaining space in proportion to its flex factor (1fr). */
child 1
child 2
child 3
child 4
Further reading about grid layouts - https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout
.grid-container-panel { display: grid; grid-template-rows: 150px 1fr 157px; /* - header row will be 150px tall, - center row will stretch (center row contains 3 panels; left,center,right) - footer row will be 150px tall, */ grid-template-columns: 200px 1fr 185px; /* - left column (vis left panel in center row) will be 200px wide, - center column (vis center panel) will stretch. - right column will be 185px wide */ height:100%; width:100%; grid-gap:3px; padding:3px; box-sizing:border-box; } .grid-container-panel div { background-color: orange; color: navy; border-radius: 0.5rem; padding:17px; } .grid-container-panel .header-row { grid-column: 1 / 4; grid-row: 1 / 2; /* span columnar-grid-line 1..4 (ie all cols) span row-grid-line 1..2 (ie row 1) */ } .grid-container-panel .left-panel { grid-column: 1 / 2; grid-row: 2 / 3; /* span columnar-grid-line 1..2 (ie col 1) span columnar-grid-line 1..2 (ie col 1) */ } .grid-container-panel .center-panel { grid-column: 2 / 3; grid-row: 2 / 3; /* span columnar-grid-line 2..3 (ie col 2) span row-grid-line 2..3 (ie row 2) */ } .grid-container-panel .right-panel { grid-column: 3 / 4; grid-row: 2 / 3; /* span columnar-grid-line 3..4 (ie col 3)*/ /* span row-grid-line 2..3 (ie row 2) */ } .grid-container-panel .footer-row { grid-column: 1 / 4; grid-row: 3 / 4; /* span columnar-grid-line 1..4 (ie all cols) span row-grid-line 3..4 (ie row 3) */ }
HEADER ROW (occupies columns 1..3 and row 1)
Left Panel
(col01 =200px; row 2)

Center Panel
(col02 Strecthy; row 2)

Right Panel
(col03 =170px;
row 2)

Further reading about grid & repeat - https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout#nesting_grids
.grid-container-of-tile { display:grid; grid-template-columns: repeat(auto-fit, 200px); } .tile { display:grid; position:relative; grid-template-rows: 40px 110px 1fr; grid-template-columns: auto; width:150px; height:auto; border:1px solid black; border-radius:5px; padding: 5px; margin: 5px; } .tile h3 { margin:0; padding:0 0 0 3px; line-height:1.2rem; font-size: 1.2rem; background-color:navy; color:white; } .tile-image { display:grid; justify-content:center; }