The only CSS-only solution I could think of makes the following assumptions:
- Your users are using up-to-date browsers, supporting the adjacent-sibling selector.
- Your right-column appears before the main-content column.
The approach, demonstrated below, works using pure css, however it also uses jQuery to effect the removal (from the DOM) and recreation (in the DOM) of the right-column: jQuery does not affect/effect the styling, or dimensions, of any content (though it does also toggle the text in the link by which the column is removed/recreated).
That said, demonstration html mark-up is below:
<div id="contentWrap">
<div id="sidebar">
<!-- navigation -->
</div>
<div id="rightColumnAndMainContent">
<div id="rightColumn">
<h2>References</h2>
<!-- a list of links -->
</div>
<div id="mainContent">
<p><!-- Lorem ipsum text in the demo... --></p>
</div>
</div>
<div id="footer">
<p><a href="#" class="remove">Remove the footer</a></p>
</div>
And the CSS:
#contentWrap {
width: 900px;
}
#sidebar {
float: left;
width: 110px;
}
#rightColumnAndMainContent {
position: relative;
margin-left: 120px;
}
#rightColumn {
position: absolute;
top: 0;
right: 0;
bottom: 0;
background-color: #f00;
width: 140px;
}
#mainContent {
background-color: #ffa;
margin-right: 0;
}
#rightColumn + #mainContent {
margin-right: 150px;
}
#footer {
text-align: center;
clear: both;
border-top: 6px solid rgba(0,0,0,0.6);
}
This works as the adjacent-sibling selector (#rightColumn + #mainContent is more specific than the basic id-selector (#mainContent), which means that while the #mainContent has a defined margin-right: 0; it's overruled if the #mainContent immediately follows the #rightColumn, which it can only do if the #rightColumn is present in the mark-up.
This feels kludgy, but it does work (at least within the confines of the JS Fiddle demo).
References: