Brower Electric - Commit #3 - Service Information Tree
This commit used a Bootstrap 5 Grid to build an information tree for the site.
First, I set up a container div with a width of 90vw and 5% on each side. This keeps everything in the middle and at least 90% of the width is used.
The Bootstrap 5 Grid system is a framework for flex-boxes. Basically, they set up the rows and columns classes for me, with pretty extensive responsiveness and including table/grid-like tools that let you adjust the size of the cols without sweating.
By default our cols are not flex containers, so we added d-flex and related attributes so that we can position the column content using flexbox tools.
The middle row flex-wraps in reverse so that even though it's positioned opposite the others on desktop, when wrapped, it reverses itself back to a sensible position.
The reason that I have both an image and a surrounding wrapper is so that I can flex position the image to keep it in line with the rest of the page. The border is applied to the image directly though.
The middle cols contain the lines. This was the biggest challenge. The lines are contained in a positioned (relative) wrapper stretched to fit the div. Because the wrapper is positioned but not flex, I can use absolute positioning for my line spans. This is desirable because flex positioning, which I generally like better, does not let you overlap your elements as easily. Took me more than an hour to figure out this solution.
The vertical line is 350% height in the top div, but not present in the middle div. This is to work around the row padding and stretch across all rows. The last div has a 100% height vertical line to help hide make sure the line does not cut short as the page flexes. This took me like 10 minutes to come up with but it was a satisfying fix. Maybe writing the div outside of the rows and positioning it in regard to the whole section of the page could be better though.
The CSS is comparatively simple since Bootstrap lets me do a large amount of the styling on the HTML doc.
Every row child has a top and bottom padding, additionally they position themselves across the row with equal space in between.
The linewrapper stretches to fit it's div with width and height at 100%. Because it's relatively positioned, I can play with absolutely positioned elements on the inside.
The vertline, as mentioned earlier, has 350% height, no width. a 6px black border and is absolutely positioned 50% from the left border of it's wrapper.
the hlines are similar. Absolutely positioned 50% to the left or right of the wrapper, with a 3px solid black border. The width of the line is 60% so it goes through and under the image. The treeimageWrapper has a z-index of 4 so that the lines go under it.
The treeimage has a 3px black border.
I added one media query to the tree images to make sure they are at least 30% of the viewport in terms of width on desktop. Without this, you get some baby-sized images.
I think that learning to develop is a lot like learning to play chess. When you practice chess, you get better in two ways: 1) You get used to stretching your brain in the chess direction and 2) You have at least some memory of how you have solved similar problems in the past.
It took me a few hours to write, what I realize now that I review it, is a small amount of code. I'd say more than 50% of the code I write, I delete and rewrite before I actually solve the problem. I think that as I solve more problems like this, my memory of their eccentricities will strengthen and I will be able to write quick solutions because, well, I've already solved it.
You can visit the site's github repository here: https://github.com/Xacheri/BrowerElectric