First, try changing the display in body to grid. Then try adding grid-template-rows and grid-template-columns to the body as well. There you can give the width and height that you would like each row and column to have; example grid-template-columns: 150px 150px or grid-template-rows: 150px 150px. Then take off the width and height for each of the colored boxes (as that is now already taken care of). Then you can add grid-row-start, grid-row-end, grid-column-start, and grid-column-end to each of the colored boxes indicating where you would like them placed on the grid. For example, you would want the blue box to have grid-column-start: 1, grid-row-start: 1, and grid-row-end: 3 so that it starts at the first column as well as the first row but goes down 2 rows to end at the start of the third. Hope this helps. My sample code is below.
► - indicates properties I haven’t seen previously
Thank you so much for taking the time to write out all those lines of code as well as providing me with such a detailed account of the rationale behind the coding. Your answer will have me going back to the books so to speak since I am not familiar with any of the properties that I have indicated with the triangles. I have completed the -
Basic HTML and HTML5
Basic CSS
Applied Visual Design
courses offered through freeCodeCamp and nowhere in those 3 blocks of lessons, have I come across the properties that I’ve designated with the triangles. I guess the reason for that must be that my courses thus far have been basic and your coding must consist of more advanced properties. I had been wondering about how I was going to layout a nice format for a web page with the items I learned in the courses. It just seemed to be an impossible task with what I knew thus far. I’m excited with the codes that you have provided me with. This seems to be the key to getting the page layout that I need for a nice looking web page. Now I am off to study!
I have - I think, implemented your suggestion in my enclosed code and it works very nicely, showing that there is more than one way to skin a cat. And thanks for the links!
After taking a few of the grid modules in the curriculum, I have attempted to implement the grid outline that I have posted previously with this code but as you can see - the result, while sort of OK in that it follows the general outline of the grid - it lacks the precision that I was looking for. For example - the container (body) was set to
height 700
the following elements had heights of
red 200
yellow 300
green 200
total 700
so they should have fit perfectly within the height of the container. But no - it’s messy with gaps where there shouldn’t be any. Similarly the blue extends beyond the container’s bottom while the orange block extends beyond the RS of the container. Any ideas as to why I’m not getting the precision fit that I was after?
If you set dimensions on the grid container you either have to add the border to the height and width, or you need to remove the box-sizing. But I would suggest you size the container using the rows and columns.
You need a row that is 300px so you can’t just divide 700 by 3.
Use the rows and columns for sizing the grid cells, you do not need to set the size of the elements.
I would suggest when practicing line placement to be explicit about the placement, even if/when not needed (define all start/end). I would also strongly suggest using the grid inspector in Chrome or Firefox. The one in Firefox is still better, but the one in Chrome does the job.
Right - I think that I was making the situation more complex than it had to be by setting width and height of the elements. Much easier to do it as you have suggested - size the grid cells and then place the elements in the grid where you want them with the grid-row / grid-column properties.
Thanks for the insights!