The Setup
I'm making a website with a simple 2 column layout. The columns will be of varying height (one taller than the other) and dynamic height (each page's content is different). The two columns' background color should extend down to the lowest point of the longest column's content.
For the visual learners among you, CSS-Tricks has some nice illustrations
The Attempt
I'm using the One True Layout Method, mentioned on the same CSS-Tricks page about half way down.
I've recreated it on jsFiddle here.
Here is the relevant coding
HTML
<a href="#area1">Go To Section 1</a>
<a href="#area2">Go To Section 2</a>
<a href="#area3">Go To Section 3</a>
<div id="hold">
<div id="col1">
Content Column 1
</div>
<div id="col2">
Content Column 2
<h2 id="area1">Section 1</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
<h2 id="area2">Section 2</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
<h2 id="area3">Section 3</h2>
<img src="http://placehold.it/100x750" alt=" placehold img" />
</div>
</div>
CSS
#hold{
height:100%;
overflow-y:hidden;
}
#col1, #col2{
padding-bottom:100000px;
margin-bottom:-100000px;
}
#col1{
float:left;
width:200px;
}
#col2{
margin-left:200px;
}
What Works?
The layout works entirely as expected. The column heights adapt to dynamic content and always remain the same height as each other.
The Problem
Anchors break it. That is to say, the page scrolls down to the proper anchor in the content, but everything above the anchor is hidden. I learned this is due to overflow-y:hidden;
- the page is scrolling down to the content and instead of using a scroll bar it's hiding the above content and not just scrolling past it. Disabling overflow:hidden
shows all content as expected, but this is not ideal due to the large bottom padding.
Other's have experienced this same problem with no recognized solutions that I could find.
Possible Solutions
I could put together a quick height check in JavaScript and set each column accordingly, but I'd really like to keep overall site layout JS free.
Some articles had mentioned absolute positioning fixed, but this won't work with dynamic content.
Change to a different column height method. But... but... but I already have this one so far! And who are we to simply cave in to an impossible a difficult coding challenge.. :)
The Call for Aid
Any ideas, fellow programmers?