I have a site with the following structure:
<div id="header"></div>
<div id="main">
<div id="navigation"></div>
<div id="content"></div>
</div>
<div id="footer"></div>
The navigation
is on the left and the content
div
is on the right. The information for the content
div
is pulled in through PHP, so it's different every time.
How to scale the navigation
vertically so that its height is the same as the content div
's height, no matter which page is loaded?
Add
display: grid
to the parentThere is a bit of a contradiction in the question's title and the content. The title speaks of a parent div, but the question makes it sound like you want two sibling divs (navigation and content) to be the same height.
Do you (a) want both navigation and content to be 100% the height of main, or (b) want navigation and content to be be same height?
I'll assume (b)...if that is so, I don't think you will be able to do it given your current page structure (at least, not with pure CSS and no scripting). You would probably need to do something like:
and set the content div to have a left margin of whatever the width of the navigation pane is. That way, the content's content is to the right of the navigation and you can set the navigation div to be 100% of the content's height.
EDIT: I'm doing this completely in my head, but you would probably also need to set the navigation div's left margin to a negative value or set it's absolute left to 0 to shove it back to the far left. Problem is, there are many ways to pull this off but not all of them are going to be compatible with all browsers.
You use CSS Flexbox
If you don't mind the navigation div being clipped in the event of an unexpectedly-short content div, there's at least one easy way:
Elsewise there's the faux-columns technique.
Based on the method described in this article I have created .Less dynamic solution:
Html:
Less:
My solution: