Feb 14

Example Double BorderRecently, A List Apart posted "Multi-Column Layouts Climb Out of the Box", an article featuring the ingenius approach of multi-columns of equal height utilizing borders and negative margins. Read: No JavaScript! This is a perfect approach if you wish a sidebar of a single color. However, what if you wish for a border between content and sidebar? You have already used the border CSS property, so how could one accomplish this look?

The answer, although not utilizing ideal semantic design in the XHTML tree, resides in a nested div in the main content column.

View it in action!
I always name my sidebar div id "secondary-content" and my main content div id "primary-content". To create this effect, I created an id "primary-content-inner" inside #primary-content.

The thick border and margin-left styles are applied to #primary-content. However, the margin-left negative margin must increase by the width of the additional thin border (the black border in my example). In like manner, the width of #primary-content-inner must be reduced by the width of the additional border. #primary-content-inner carries the style for the additional thin border (as border-left here).
You also must apply the thin additional border to #secondary-content - a border-right in my example. You must add it here in case the sidebar is longer than #primary-content.
The only catch I could discern is that you must set your p tags to margin-bottom:0;. If anything inside #primary-content-inner has a margin-bottom, the thin border will not extend to the bottom of #primary-content, as the margins are outside of the borders. In effect, you will be making #primary-content larger than #primary-content-inner by the height of the margin-bottom of the last element, and thus your borders will not align.

The CSS:

CSS:
  1. /* I usually start with *,html margin and padding to zero. Then I reset it to what I actually want later. This eliminates the margin-bottom on p tags */
  2. *,html{
  3. margin:0;
  4. padding:0;
  5. }
  6. /* I do want some spacing on p tags, so I create it here. Alter it to your choice - padding does not disrupt the borders */
  7. p{
  8. padding:5px;
  9. }
  10.  
  11. #container{
  12. margin:0 auto;
  13. width:700px;
  14. }
  15. /* Settings widths are necessary. See the ALA article for detail on liquid and elastic layouts. */
  16. #primary-content{
  17. border-left:225px #ccc solid;
  18. float:right;
  19. margin-left:-227px;
  20. width:475px;
  21. }
  22. #primary-content-inner{
  23. border-left:2px solid #000;
  24. width:473px;
  25. }
  26. #secondary-content{
  27. background-color:#ccc;
  28. border-right:2px #000 solid;
  29. float:left;
  30. width:225px;
  31. }

The HTML:


HTML:
  1. <div id="container">
  2.    <div id="primary-content">
  3.       <div id="primary-content-inner">
  4.          Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  5.       </div><!-- /primary-content-inner -->
  6.    </div><!-- /primary-content -->
  7.    <div id="secondary-content">
  8.       Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  9.    </div><!-- /secondary-content -->
  10. </div><!-- /container -->

View it in action!

Leave a Reply