This is an example of taking one of the popular three-column CSS layouts from BlueRobot.com and adding a little javascript to enable collapsible left and right columns.
The purpose of this exercise is to utilize a proven CSS layout without modifying the original CSS or original html structure.
The xToolbar demo also makes use of this CSS layout.
Enjoy, Mike Foster
updated: 12Jan07
Discussion
After several questions about this demo, and the related dockable nav technique, I will try to provide a few answers below. I'm glad this demo has been useful to you. Thanks for your comments and feedback.
Types of 'Dockable Navs'
Basically I've seen two different types of dockable navs:
The element is not a part of the page layout (except when Javascript is disabled) and slides in on top of the visible page. In this technique the nav element is loosely bound to the HTML structure and so we have more freedom in implementing a generic Javascript solution that might also work with other page layouts.
The element is part of the page layout and showing or hiding the element causes the remainder of the page to collapse or expand. In this technique the nav element is tightly bound to the HTML structure and so our Javascript solution will have to make assumptions about widths and margins for specific elements. This specific solution will not work with other page layouts. [altho... as I type this I'm getting ideas for ways to abstract this also ;-)]
These two are implemented very differently. Cross-Browser.com and SitePoint.com use technique #2, and this page illustrates the basic ideas behind that technique.
How This Page Works
The fundamental HTML structure for this page consists of any number of relatively positioned content elements (these make up the center column), followed by two absolutely positioned elements navAlpha and navBeta which make up the left and right columns.
These layout elements have their position and size specified with CSS. The content elements have width:auto and have left and right margins which provide enough space for the navAlpha and navBeta columns which are given specific widths corresponding to the content margins. The left and right columns are positioned absolutely in their respective top-left and top-right corners of the page. The width of the center column (the content elements) is determined by the inner width of the window minus the widths (and margins) of the left and right columns.
With Javascript we can cause the right column to not be rendered by setting its style.display property to 'none' (try it / undo it). Since navBeta is absolutely positioned it is not in the flow of HTML and when it is no longer rendered this has no effect on how the remaining elements are rendered. The content elements have a right margin which leaves enough space for navBeta - so in addition to setting navBeta's display to 'none' we must also adjust the content elements' right margin so they will expand to fill the empty space left by navBeta. And that's how this page works (toggle left and right columns).
Lk 6:27-36 "But I say to you who are hearing, Love your enemies, do good to those hating you, bless those cursing you, and pray for those accusing you falsely; and to him smiting thee upon the cheek, give also the other, and from him taking away from thee the mantle, also the coat thou mayest not keep back. And to every one who is asking of thee, be giving; and from him who is taking away thy goods, be not asking again; and as ye wish that men may do to you, do ye also to them in like manner; and -- if ye love those loving you, what grace have ye? for also the sinful love those loving them; and if ye do good to those doing good to you, what grace have ye? for also the sinful do the same; and if ye lend to those of whom ye hope to receive back, what grace have ye? for also the sinful lend to sinners -- that they may receive again as much. But love your enemies, and do good, and lend, hoping for nothing again, and your reward will be great, and ye shall be sons of the Highest, because He is kind unto the ungracious and evil; be ye therefore merciful, as also your Father is merciful."
13 Jesus said to his disciples, "Compare me to something and tell me what I am like." Simon Peter said to him, "You are like a just messenger." Matthew said to him, "You are like a wise philosopher." Thomas said to him, "Teacher, my mouth is utterly unable to say what you are like." Jesus said, "I am not your teacher. Because you have drunk, you have become intoxicated from the bubbling spring that I have tended."