{"id":9148,"date":"2022-10-13T13:14:44","date_gmt":"2022-10-13T12:14:44","guid":{"rendered":"https:\/\/stevepedwards.today\/DebianAdmin\/?p=9148"},"modified":"2023-10-28T23:54:07","modified_gmt":"2023-10-28T22:54:07","slug":"css-grid-layouts","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/DebianAdmin\/css-grid-layouts\/","title":{"rendered":"CSS Grid Layouts"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_9148\" class=\"pvc_stats all  \" data-element-id=\"9148\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Grid is similar to Flex in that you tell it what layout style you want, but in form of columns and rows. In this case there are 3 columns with column 2 twice the width of 1 and 3:<\/p>\n<pre class=\"lang:default decode:true \">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;style&gt;\r\n        .item {\r\n            border: 1px solid #333;\r\n            background-color: #777;\r\n            color: yellow;\r\n        }\r\n\r\n        \/* you modify a container for the grid model layout, similarly as you would for flex then it acts on all the children. Default IS 2D top to\r\n        bottom layout anyway, so stacked items don't change initially, so appears to do nothing here until you tell it which columns exist and what \r\n        size to be with grid-template-columns, then it affects the children in that container*\/\r\n        .container {\r\n            display: grid;\r\n            \/* only 2 columns are defined here, so div2 wraps up to div1 line. div3 stays in column 1 same size as div1  *\/\r\n            \/* grid-template-columns: 100px 50px;\r\n            grid-template-rows: 50px 100px; *\/\r\n            \/* if above is commented out, you can do same defining rows and columns at same time. Not so clear what happens *\/\r\n            \/* grid-template: 50px 100px \/ 100px 100px  *\/\r\n            \/* auto rows defines a default for undefined rows - same as auto and same for columns *\/\r\n            \/* grid-auto-rows: auto; *\/\r\n            \/* grid-template-rows: 50px;\r\n            grid-auto-rows: 150px; *\/\r\n            \/* another format is fractional: the width divides up 3 columns below, into quarters of total width with middle column at 1\/2 width, start and end columns of 1\/4 width*\/\r\n            <strong><span style=\"color: #ff0000;\">grid-template-columns: 1fr 2fr 1fr;<\/span><\/strong>\r\n            \/* row-gap: 20px;\r\n            column-gap: 20px; *\/\r\n            \/* the 2 above lines can be done by *\/\r\n            gap: 20px;\r\n        }\r\n\r\n        .item1 {\r\n\r\n        }\r\n\r\n        .item2 {\r\n\r\n        }\r\n\r\n        .item3 {\r\n\r\n        }\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"container\"&gt;\r\n        &lt;div class=\"item item1\"&gt;1&lt;\/div&gt;\r\n        &lt;div class=\"item item2\"&gt;2&lt;\/div&gt;\r\n        &lt;div class=\"item item3\"&gt;3&lt;\/div&gt;\r\n        &lt;div class=\"item item4\"&gt;4&lt;\/div&gt;\r\n        &lt;div class=\"item item5\"&gt;5&lt;\/div&gt;\r\n        &lt;div class=\"item item6\"&gt;6&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n    \r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>The inline block divs, 1-6, that want to take up a whole column to themselves auto fit the grid template format up to the available view width and auto size with browser resize:<\/p>\n<p>grid-template-columns: 1fr 2fr 1fr;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9152 size-medium\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/GridCols.png\" alt=\"\" width=\"821\" height=\"450\" \/><\/p>\n<p>The row height can also be set similarly. Row 2 is twice the height of row 1:<\/p>\n<div>\n<div>grid-template-rows: 50px 100px;<\/div>\n<\/div>\n<div><\/div>\n<div>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            \/* only 2 columns are defined here, so div2 wraps up to div1 line. div3 stays in column 1 same size as div1  *\/\r\n            \/* grid-template-columns: 100px 50px;\r\n            grid-template-rows: 50px 100px; *\/\r\n            \/* if above is commented out, you can do same defining rows and columns at same time. Not so clear what happens *\/\r\n            \/* grid-template: 50px 100px \/ 100px 100px  *\/\r\n            \/* auto rows defines a default for undefined rows - same as auto and same for columns *\/\r\n            \/* grid-auto-rows: auto; *\/\r\n            \/* grid-template-rows: 50px;\r\n            grid-auto-rows: 150px; *\/\r\n            \/* another format is fractional: the width divides up 3 columns below, into quarters of total width with middle column at 1\/2 width, start and end columns of 1\/4 width*\/\r\n            <span style=\"color: #ff0000;\"><strong>grid-template-columns: 1fr 2fr 1fr;\r\n            grid-template-rows: 50px 100px;<\/strong><\/span>\r\n            \/* row-gap: 20px;\r\n            column-gap: 20px; *\/\r\n            \/* the 2 above lines can be done by *\/\r\n            gap: 20px;\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9154 size-medium\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/GridRows.png\" alt=\"\" width=\"821\" height=\"450\" \/><\/p>\n<\/div>\n<p>For any undefined rows or columns added to the HTML, the default is same as:<\/p>\n<p>\/* auto rows defines a default for undefined rows - same as auto and same for columns *\/ \/*<\/p>\n<pre class=\"lang:default decode:true\"><span style=\"color: #ff0000;\">grid-template-columns: 1fr 2fr;<\/span> \r\n<span style=\"color: #ff0000;\">grid-template-rows: 50px;<\/span><\/pre>\n<p>The undefined rows default to the min div height for their row:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9156 size-medium\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/ExtraRows.png\" alt=\"\" width=\"821\" height=\"450\" \/><\/p>\n<p>Notice that the extra undefined rows of divs 5+6 are also the same height as row 2 because only the first row is defined at 50px so all those after cycle back round to a default value of 18px shown in DevTools F12:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9158 size-medium\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/DefDivHeight18px.png\" alt=\"\" width=\"1921\" height=\"1033\" \/><\/p>\n<p>Grid auto flow is similar to Flex direction in changing the axes by which the elements fill the page space - by row or column:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-auto-flow: column;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9162 \" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/AutoColumns.png\" alt=\"\" width=\"719\" height=\"470\" \/><\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-auto-flow: row;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9164\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/AutoRows.png\" alt=\"\" width=\"771\" height=\"504\" \/><\/p>\n<p>You can pre-define grid areas by name then fit a particular div item to that area:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 100px 250px;\r\n            grid-template-rows: 50px 100px;\r\n            <span style=\"color: #ff0000;\">grid-template-areas: \r\n            \"header header\"\r\n            \"sidebar content\";<\/span>\r\n        }\r\n\r\n        <span style=\"color: #ff0000;\">.item1 {\r\n            grid-area: header;\r\n        }\r\n\r\n        .item2 {\r\n            grid-area: sidebar;\r\n        }\r\n\r\n        .item3 {\r\n            grid-area: content;\r\n        }<\/span><\/pre>\n<p>item 1 fills the space named header, so takes two columns.<\/p>\n<p>item 2 fills the sidebar area, item 3 the content area:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9166\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/templateareas.png\" alt=\"\" width=\"722\" height=\"472\" \/><\/p>\n<p>Again the overflow divs default to the values for the defined two columns widths:<\/p>\n<p><span style=\"color: #ff0000;\">grid-template-columns: 100px 250px;<\/span><\/p>\n<p>but with default heights of 18px for elements 4, 5,and 6. You see the similarity of this aspect of Grid to Flex here.<\/p>\n<p>A period can be used to denote \"anything\" to filler to an undecided category:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 100px 150px 50px;\r\n            grid-template-rows: 50px 100px;\r\n            grid-template-areas: \r\n            \"header header header\"\r\n            <span style=\"color: #ff0000;\">\"sidebar content .\";<\/span>\r\n        }\r\n\r\n        .item1 {\r\n            grid-area: header;\r\n        }\r\n\r\n        .item2 {\r\n            grid-area: sidebar;\r\n        }\r\n\r\n        .item3 {\r\n            grid-area: content;\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9170\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/filler.png\" alt=\"\" width=\"755\" height=\"493\" \/><\/p>\n<p>Div 4 fills the . area of :<\/p>\n<div>\n<div><span style=\"color: #ff0000;\">\"header header header\"<\/span><\/div>\n<div><span style=\"color: #ff0000;\">\"sidebar content .\";<\/span><\/div>\n<\/div>\n<div><\/div>\n<div>Another method Grid uses to count areas is by the line between cells.<\/div>\n<div>The page left border is line 1. It can also count from the opposite page side using negative numbers, so the right edge is -1. With 8 elements (divs) and 3 columns, with 2 rows defined, we have:<\/div>\n<div><\/div>\n<div>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-template-columns: 100px 50px 75px;\r\n            grid-template-rows: 50px 100px;<\/span>\r\n        }\r\n\r\n        .item1 {\r\n        }\r\n\r\n        .item2 {\r\n        }\r\n\r\n        .item3 {\r\n        }<\/pre>\n<p>So, row 1 is 50px high, row 2 is 100px high.<\/p>\n<p>Column 1 is 100px wide, column 2 is 50px wide, column 3 is 75px wide:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9172\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/CellEdgeCount.png\" alt=\"\" width=\"805\" height=\"526\" \/><\/p>\n<p>So, to have item1 span 2 columns, you count the cell walls from left, so will start at 1 and end at 3:<\/p>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            <span style=\"color: #ff0000;\">grid-column-start: 1;\r\n            grid-column-end: 3;<\/span>\r\n        }<\/pre>\n<p>This shows item 1 spanning 2 columns:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9174\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/2cols.png\" alt=\"\" width=\"771\" height=\"504\" \/><\/p>\n<p>The same result from:<\/p>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            <span style=\"color: #ff0000;\">grid-column-start: 1 \/ 3<\/span>\r\n        }<\/pre>\n<p>The same format applies to rows top to bottom:<\/p>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            <span style=\"color: #ff0000;\">grid-column-start: 1;\r\n            grid-column-end: 3;\r\n            grid-row-start: 1;\r\n            grid-row-end: 3;<\/span>\r\n        }<\/pre>\n<p>This causes item 1 to start at page top cell border and end at row 3 border:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9177\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/2rows.png\" alt=\"\" width=\"808\" height=\"528\" \/><\/p>\n<\/div>\n<div>Or:<\/div>\n<div><\/div>\n<div>\n<pre class=\"lang:default decode:true\">.item1 { \r\n<span style=\"color: #ff0000;\">grid-column-start: 1 \/ 3\r\ngrid-row-start: 1 \/ 3<\/span> \r\n}<\/pre>\n<p>You can place any item in any row:<\/p>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            grid-column-start: 1 \/ 3;\r\n            <span style=\"color: #ff0000;\">grid-row: 2 ;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9180\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/ItemInRow.png\" alt=\"\" width=\"810\" height=\"529\" \/><\/p>\n<\/div>\n<div>To make an element span 2 rows:<\/div>\n<div><\/div>\n<div>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            grid-column-start: 1 \/ 3;\r\n            <span style=\"color: #ff0000;\">grid-row: span 2;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9183\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/Span2.png\" alt=\"\" width=\"856\" height=\"559\" \/><\/p>\n<p>Same for columns:<\/p>\n<pre class=\"lang:default decode:true\">.item1 { \r\n<span style=\"color: #ff0000;\">grid-column-start: span 2;<\/span> \r\ngrid-row: span 2; \r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9184\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/SpanBoth.png\" alt=\"\" width=\"660\" height=\"431\" \/><\/p>\n<p>A way to make item 1 fill 2 rows AND columns is confusing at first:<\/p>\n<pre class=\"lang:default decode:true\">.item1 {\r\n            <span style=\"color: #ff0000;\">grid-column: 1 \/ -1 ;\r\n            grid-row: 1 \/ -1 ;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9185\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/2x2.png\" alt=\"\" width=\"794\" height=\"519\" \/><\/p>\n<p>This works because the -1 row is at the START of the only 2nd row defined in the initial container:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 100px 50px 75px;\r\n            <span style=\"color: #ff0000;\">grid-template-rows: 50px 100px;<\/span>\r\n        }<\/pre>\n<p>So the bottom edge of row 2 (100px row)= -1 of those defined so countable. The rest are overflow at row height defaults.<\/p>\n<p>A powerful method similar to flex-grow uses fractional ratios for column widths:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-template-columns: 1fr 2fr 1fr;<\/span>\r\n            grid-template-rows: 50px 100px;\r\n        }\r\n\r\n        .item1 {\r\n\r\n        }\r\n\r\n        .item2 {\r\n        }\r\n\r\n        .item3 {\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9187\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/FRCols.png\" alt=\"\" width=\"768\" height=\"502\" \/><\/p>\n<p>The centre column is twice the width of cols 1 and 3 as the whole page width is divided into 4 equal widths then shared by the defined proportions <span style=\"color: #ff0000;\">1fr 2fr 1fr;<\/span><\/p>\n<p>Other self explanatory formats like:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-template-columns: 50px repeat(2, 1fr) 50px;\r\n            grid-template-rows: 50px 50px;<\/span>\r\n        }<\/pre>\n<p>gives a grid of:<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9189\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/repeats.png\" alt=\"\" width=\"725\" height=\"474\" \/><\/p>\n<p>For these cells to be used for actual content, a min height can be specified,\u00a0 and so that larger text amounts will be accomodated automatically from the above layout to a view that expands according to the text:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 50px repeat(2, 1fr) 50px;\r\n            <span style=\"color: #ff0000;\">grid-template-rows: minmax(50px, auto) 50px;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9190\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/minmax.png\" alt=\"\" width=\"748\" height=\"569\" \/><\/p>\n<p>A property that grid has that flex does not, is row-gap and column-gap for spacing between cells:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 50px repeat(2, 1fr) 50px;\r\n            grid-template-rows: minmax(50px, auto) 50px;\r\n            <span style=\"color: #ff0000;\">row-gap: 10px;\r\n            column-gap: 10px;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9191\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/Gaps.png\" alt=\"\" width=\"706\" height=\"537\" \/><\/p>\n<p>That can be shortened for same result for rows AND columns to just gap:<\/p>\n<pre class=\"lang:default decode:true\">display: grid;\r\n            grid-template-columns: 50px repeat(2, 1fr) 50px;\r\n            grid-template-rows: minmax(50px, auto) 50px;\r\n            \/* row-gap: 10px;\r\n            column-gap: 10px; *\/\r\n            <span style=\"color: #ff0000;\">gap: 10px;<\/span>\r\n        }<\/pre>\n<p>It's possible to align the total grid content to top left, within it's parent container with justify-content :<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 50px 100px 50px;\r\n            \/* grid-template-rows: .5fr .5fr .5fr; *\/\r\n            \/* row-gap: 10px;\r\n            column-gap: 10px; *\/\r\n            gap: 10px;\r\n            <span style=\"color: #ff0000;\">justify-content: start;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9194\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/justStart.png\" alt=\"\" width=\"721\" height=\"941\" \/><\/p>\n<div>\n<div><span style=\"color: #ff0000;\">justify-content: center;<\/span><\/div>\n<\/div>\n<div><\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9195\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/justCenter.png\" alt=\"\" width=\"690\" height=\"900\" \/><\/div>\n<div>Similarly for align along the X axis if the grid is large enough for spacing the content:<\/div>\n<div>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: 50px 100px 50px;\r\n            \/* grid-template-rows: .5fr .5fr .5fr; *\/\r\n            \/* row-gap: 10px;\r\n            column-gap: 10px; *\/\r\n            gap: 10px;\r\n            <span style=\"color: #ff0000;\">justify-content: center;\r\n            height: 400px;\r\n            border: 10px solid black;\r\n            align-content: center;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9196\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/alignCenter.png\" alt=\"\" width=\"786\" height=\"877\" \/><\/p>\n<\/div>\n<div>As the default row\/col align is :stretch, the cells go to top left and fill available defined column heights.<\/div>\n<div>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-template-columns: 50px 100px 50px;<\/span>\r\n            \/* grid-template-rows: .5fr .5fr .5fr; *\/\r\n            \/* row-gap: 10px;\r\n            column-gap: 10px; *\/\r\n            gap: 10px;\r\n            <span style=\"color: #ff0000;\">justify-content: stretch;<\/span>\r\n            height: 400px;\r\n            border: 10px solid black;\r\n            <span style=\"color: #ff0000;\">align-content: stretch;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9197\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/stretchstart.png\" alt=\"\" width=\"641\" height=\"715\" \/><\/p>\n<\/div>\n<div>Align in Grid is the X horizontal axis:<\/div>\n<div><\/div>\n<div>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: repeat(3, 100px);\r\n            grid-template-rows: minmax(50px, auto) 100px;\r\n            gap: 10px;\r\n            height: 400px;\r\n            border: 10px solid black;\r\n            <span style=\"color: #ff0000;\">align-content: start;<\/span>\r\n            <span style=\"color: #ff0000;\">justify-content: start;<\/span>\r\n            <span style=\"color: #ff0000;\">align-items: center;<\/span>\r\n        }\r\n\r\n        .item1 {\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9199\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/alignItemsCenter.png\" alt=\"\" width=\"651\" height=\"834\" \/><\/p>\n<p>Everything centered:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-template-columns: repeat(3, 100px);\r\n            grid-template-rows: minmax(50px, auto) 100px;\r\n            gap: 10px;\r\n            height: 400px;\r\n            border: 10px solid black;\r\n            <span style=\"color: #ff0000;\">align-content: center;\r\n            justify-content: center;\r\n            align-items: center;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9200\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/allcentered.png\" alt=\"\" width=\"671\" height=\"763\" \/><\/p>\n<p>Individual cells can be aligned with align:self:<\/p>\n<pre class=\"lang:default decode:true\">&lt;style&gt;\r\n        .item {\r\n            border: 1px solid #333;\r\n            background-color: #777;\r\n            color: yellow;\r\n        }\r\n\r\n        \/* you modify a container for the grid model layout, similarly as you would for flex then it acts on all the children. Default IS 2D top to\r\n        bottom layout anyway, so stacked items don't change initially, so appears to do nothing here until you tell it which columns exist and what \r\n        size to be with grid-template-columns, then it affects the children in that container*\/\r\n        .container {\r\n            display: grid;\r\n            grid-template-columns: repeat(3, 100px);\r\n            grid-template-rows: minmax(50px, auto) 100px;\r\n            gap: 10px;\r\n            height: 400px;\r\n            border: 10px solid black;\r\n            align-content: flex-start;\r\n            justify-content: start;\r\n            align-items: flex-start;\r\n        }\r\n\r\n        <span style=\"color: #ff0000;\">.item1 {\r\n            align-self: flex-start;\r\n        }\r\n\r\n        .item2 {\r\n            align-self: stretch;\r\n        }\r\n\r\n        .item3 {\r\n            align-self: flex-end;\r\n        }\r\n\r\n        .item4 {\r\n            align-self: flex-start;\r\n        }\r\n        .item5 {\r\n            align-self: center;\r\n        }<\/span>\r\n    &lt;\/style&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9202\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/AlignSelf.png\" alt=\"\" width=\"650\" height=\"739\" \/><\/p>\n<p>Gaps can be filled in if a cell can fit in a space using:<\/p>\n<p><span style=\"color: #ff0000;\">grid-auto-flow: dense;<\/span><\/p>\n<p>but the HTML flow order will be out of order. Going from 1,2,3 to 1,3,2:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            <span style=\"color: #ff0000;\">grid-auto-flow: row;<\/span>\r\n            grid-template-columns: <span style=\"color: #ff0000;\">repeat(3, 100px);<\/span>\r\n            grid-template-rows: minmax(50px, auto) 100px;\r\n            gap: 15px;\r\n            border: 5px solid black;\r\n            \r\n        }\r\n\r\n        .item1 {\r\n            <span style=\"color: #ff0000;\">grid-column: span 2<\/span>;\r\n        }\r\n\r\n        .item2 {\r\n            <span style=\"color: #ff0000;\">grid-column: span 2;<\/span>\r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9204\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/autoflowrow.png\" alt=\"\" width=\"738\" height=\"666\" \/><\/p>\n<p>If dense is used, item 3 will be flowed to take up the space next to item 1:<\/p>\n<pre class=\"lang:default decode:true\">.container {\r\n            display: grid;\r\n            grid-auto-flow: <span style=\"color: #ff0000;\">dense<\/span>;\r\n            grid-template-columns: repeat(3, 100px);\r\n            grid-template-rows: minmax(50px, auto) 100px;\r\n            gap: 15px;\r\n            border: 5px solid black;\r\n            \r\n        }<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-9205\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/uploads\/2022\/10\/dense.png\" alt=\"\" width=\"719\" height=\"649\" \/><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_9148\" class=\"pvc_stats all  \" data-element-id=\"9148\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Grid is similar to Flex in that you tell it what layout style you want, but in form of columns and rows. In this case there are 3 columns with column 2 twice the width of 1 and 3: &lt;!DOCTYPE html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt; &lt;style&gt; .item { border: 1px solid #333; background-color: #777; color: yellow; <a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/css-grid-layouts\/\" class=\"more-link\">...<span class=\"screen-reader-text\">\u00a0 CSS Grid Layouts<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-9148","post","type-post","status-publish","format-standard","hentry","category-post"],"a3_pvc":{"activated":true,"total_views":2,"today_views":0},"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/comments?post=9148"}],"version-history":[{"count":60,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9148\/revisions"}],"predecessor-version":[{"id":10083,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/9148\/revisions\/10083"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/media?parent=9148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/categories?post=9148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/tags?post=9148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}