I am one of the biggest advo­cates for CSS.  That being said, I’ve always been dis­ap­pointed in it’s lay­out capa­bil­i­ties.  There looks to be some promis­ing new fea­tures in CSS3.  How­ever, being that we’re just start­ing to think about bail­ing on IE6, it’s going to be quite a while before we can even start to rely some browsers *ehem IE ehem* to sup­port CSS3 fully.  That being said, I’d like to intro­duce a tech­nique for a col­umn divider that extends to the longest of the two columns (and is purely CSS driven).

How many times have you built a two col­umn lay­out?  How many times have you found it damn near impos­si­ble to get them to line up at the bot­tom with­out using some Javascript?  It’s a crappy sit­u­a­tion to be in.  “Rely on Javascript, do without..?”

In cer­tain sit­u­a­tions, you don’t have to decide.  Assum­ing both columns are above the same back­ground, and all that is needed between them is a one-pixel divider, then we’ve got the ticket.  The gen­eral dilemma with this sort of lay­out is that you really only get to choose one side to have the divider on.  Say you have a basic “Content/Sidebar” layout:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<html>
<head>
    <style>

    #wrap {
        width: 800px;
        padding: 10px;
        bor­der: 1px solid black;
        back­ground: lightyel­low;
    }

    #main {
        width: 600px;
        float: right;
    }

    #sec­ondary {
        width: 200px;
        float: left;
    }

    .clear { clear: both; }

    </style>
</head>
<body>
    <div id=“wrap”>
        <h1>Site Header</h1>
        <div id=“main”>
            <h2>Page Header</h2>
            <p>Lorem ipsum dolor sit amet…</p>

            <p>Pel­len­tesque scelerisque…</p>

            <p>Nunc quam eros, vulpu­tate…</p>

            <p>Cur­abitur male­suada augue…</p>

            <p>Inte­ger vitae tel­lus non…</p>
        </div>
        <div id=“sec­ondary”>
            <h3>Nav­i­ga­tion</h3>
            <ul>
                <li><a href=”#”>Home</a></li>
                <li><a href=”#”>Page #2</a></li>
                <li><a href=”#”>Page #3</a></li>
                <li><a href=”#”>Page #4</a></li>
            </ul>
        </div>
    </div>
</body>
</html>

If you add the divider to the left col­umn, then you chance the  con­tent col­umn being longer than the divider.  If you put the divider to the right col­umn, you chance it being shorter than the left col­umn, etc.  It’s just a big mess.

The solu­tion?  Add the divider to both columns.

1
2
3
4
5
6
7
8
9
10
11
12
#main {
width: 599px;
float: right;
border-left: 1px solid black;
}

#sec­ondary {
width: 199px;
float: left;
border-right: 1px solid black;
margin-right: –1px;
}

If you noticed, we pretty much did the same thing to both of the columns.  We added the divid­ing line on the sides that touched, as well as com­pen­sated the 1px bor­der in the width.  The only thing that we did dif­fer­ently was added a neg­a­tive mar­gin of one pixel to the sec­ondary col­umn on the join­ing side.  This method basi­cally over­laps both columns by one pixel.  Luck­ily, both of these columns share a one pixel bor­der on that side, caus­ing it too look like there’s only one bor­der between them.

You can see how find­ing this has saved me tons of grief, and time search­ing for the best col­umn Javascript code..

Hope this helped some­body, as it was a huge help to me!