There is no complete solution for CSS for this problem. This CSS "question" has been known for many years. Since CSS has grown in functionality over the years, I thought there might be a complete CSS solution so far. But alas, no. I tried many things and searched high and low, and the problem remained the same.
As far as I know, there are only 3 solutions for which third-party libraries are not required: absolute positioning, artificial codes (two-color repeating background) and JS.
The only two solutions that I like are artificial columns and JS. I prefer the JS solution, as it uses CSS more. With JS, you do not need to re-work with the background image if you want to change the column width or color later. This is a more adaptable and reusable solution. The only advantage I see for creating faux columns is that your layout does not break if the client disables JS.
JS solution (no wrapper required): https://jsfiddle.net/Kain52/uec9cLe4/
var side1 = document.getElementsByTagName('main')[0]; var side2 = document.getElementById('mainMenu'); var side1Height = side1.clientHeight; var side2Height = side2.clientHeight; if(side2Height < side1Height) { side2.style.height = side1Height + "px"; } else { side1.style.height = side2Height + "px"; }
JS solution (shell required): https://jsfiddle.net/Kain52/7udh55zq/
var wrapperHeight = document.getElementById('innerWrapper').clientHeight; document.getElementsByTagName('main')[0].style.height = wrapperHeight + "px"; document.getElementById('mainMenu').style.height = wrapperHeight + "px";
Explanation: If you use a wrapper div, you can assign it to the height of the wrapper. If you are not using a wrapper, you can simply set the height of the shortest side to the height of the longest side. If you know that your menu bar will always be shorter than your content, then you only need two lines of code:
var contentHeight = document.getElementsByTagName('main')[0].clientHeight; document.getElementById('mainMenu').style.height = contentHeight + "px";
source share