Skip to content

Instantly share code, notes, and snippets.

@mkantor
Last active December 17, 2015 10:38
Show Gist options
  • Save mkantor/5595880 to your computer and use it in GitHub Desktop.
Save mkantor/5595880 to your computer and use it in GitHub Desktop.
Demonstrate two column CSS table layout.
nav {
display: table-cell;
padding-right: 5px;
background: yellow;
white-space: nowrap; /* Prevent nav from ever inserting line breaks between words (like before "(p)"). */
}
#content {
display: table-cell;
padding-left: 5px;
width: 100%; /* Because of table layout, this will shrink nav to the smallest width its content can handle (similarly to how float widths work). */
}
header {
background: blue;
}
#main {
display: table;
width: 100%;
}
footer {
background: #ccc;
}
<header>
Head
</header>
<div id="main">
<nav id="main_nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/contact">Contact (p)</a></li>
<li><a href="/temp">Temp</a></li>
</ul>
</nav>
<div id="content" class="clearfix">
<h1>Test</h1>
<h2>A</h2><h2>C</h2><h2>D</h2>
</div>
</div>
<footer>
<p>[Copyright bumf]</p>
</footer>
@mkantor
Copy link
Author

mkantor commented May 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment