I’m doing a fixed sidebar that I resolved here in stack overflow, so now I have a fixed bar with this code:
<div id="main" style="width:100%;background:red;">
<div id="sidemenu" style="float:left;height:200px;background:#000;">
menu<br />
menu<br />
menu<br />
menu<br />
menu<br />
menu<br />
</div>
<div id="content" style="height:200px;overflow-y:scroll;background:silver;">
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
content <br />
</div>
</div>
It has a height of 200px (just to see how it works), but the sidebar I need has to have a height of 100% all the time. I have seen various posts here in stackoverflow that say that faux columns is a option: http://www.alistapart.com/articles/fauxcolumns/ . But inside my <div id="sidebar"> I’ll have, in some cases, 2 more DIVs: #menu and #submenu, so the width will vary.
What can I do? I don’t need support for old browsers: IE9, latest Chrome and latest Firefox is OK.
I’d add a
border-leftto the body, get the longest menu item and match it’s width in ems, then set a negative margin on the sidemenu. Then it’ll appear to match whatever height the content div takes up (either if you set it explicitly, or if content expands it):For a sidebar with a textured background (one method), you could set the width in pixels to match the width of the texture (not as flexible as ems but if set to the widest item, should be okay) and the texture repeats along the y-axis: