Two Column

Nice Design - Without Information Overload

Table of Contents

Two column layouts remain the most popular layout for most web pages on the Internet today. Usually, one column for content and one for supplementary content, without information overload.


CSS Table Layout

Main Article

Using HTML tables for layout has accessibility issues. CSS positioning techniques is a better option and a popular method is to float columns into place. Achieving full background colour on floated columns has issues and is usually resolved by using faux columns.

Another option is CSS table layouts. They do not have the accessibility problems of HTML tables or the need to faux column backgrounds.

Try resizing the browser and notice that below 40em (640px), we switch to a single column layout in order to remain mobile friendly. This is the main column containing more important information, optimised for search engines.

Two Column CSS Table Code

The markup required to achieve this layout is a parent container and two child containers. Any block-level elements will do. It is the class names that are important.

Structure

<section class="css-table">
  <h3>TITLE</h3>
  <article class="col main round">
    <h4>TITLE</h4>
    <p>PARA</p>
  </article>
  <aside class="col round">
    <h4>TITLE</h4>
    <p>PARA</p>
  </aside>
</section>

Presentation

A media query can be used to switch from a one column layout to the two column layout. You will need to decide what is the best breakpoint for your particular design but it should be around the point where the width exceeds an ideal reading line length. 40em (640px) feels right for this layout.

@media screen and (min-width: 40em) {
  /* Set the parent container as a CSS table */ 
  .css-table {
    width: 100%; /* Fluid width */
    display: table;  
    border-spacing: .6em;
  }
  /* Set the child containers as CSS table columns */  
  .col {
    display: table-cell; 
    padding: 0 2%;
  }

  .main {
    width: 65%; /* fluid 2/3rds width */ 
  }
  /* No need to set width for column two. It will use remaining width */

}

Compatibility

Check support for CSS Table display and you will see no support for IE7 and below. To fix this, we could use floats in the IE only style-sheet and use the * hack to target IE7 and below. You would need to clear these floats.

/* Over-ride parent to be an inline container */ 
.css-table { 
  *width: auto;
  *display: inline; 
}

.col{ /* Float all columns to the left */ 
  *float: left;
  *width: 24%; 
  *display: inline;
}

However, this fix was not needed in this design because IE8 and below are only receiving a basic layout.


Full-Height Column Backgrounds

Many sites use floats and have to resort to Faux Columns in order to achieve full-height backgrounds for the columns. With CSS Tables, no hacks are necessary. Let's make a couple of adjustments to the inherited properties to see how easy we can add full height backgrounds


Popular Two-Column Layout

Main Title

This is the main column which is longer than the corresponding right column.

All we need to do is set a background colour and adjust the padding slightly so the content centres in the sidebar background.

This could be any background solid colour, gradient or image. What about an SVG file (diagonal gradient) with a solid colour fall-back! We also add the round class to get a rounded, shadowed box

/* SVG Background */
    background: #ff0 url(/i/gradient.svg); 
    background-size:cover;
    

SVG (Scalable Vector graphics) allows us to do some great art work that scales without losing quality. See Resolution Independence With SVG to get started with using SVG.


Equal Width Columns

Main Header

To override the two column layout defaults (66/33), we could use an in-line or embedded style-sheet. Another option is to define additional class-names (A much better option IMO). How about equal width columns!

We could simply remove the main class but to remain a degree of control, we can add another class.


Overriding with Class-names

Here, two new class names are added to the 40em media query. One for the first column width, the other for a bit of styling (embedded style-sheet). We also add the round class to get a rounded, shadowed box. It would be easy to make adjustments to other properties, such as adjusting column gaps.

<!-- Structure -->
<section class="css-table">
  <h3>Class Overrides</h3>
  <section class="col left50">
    <h4>Main Title</h4>
    ...
  </section>
  <aside class="col round myBox">
    <h4>Information</h4>
    ...
  </aside>
</section>
/* Presentation */
@media screen and (min-width: 40em) {
  .left50 {
    width: 49%;
  }
  .myBox {
    background: #fff0d6;
  }
}
/* Legacy IE Browser Compatibility */
@media screen and (min-width: 40em) {
  .left50 {
    *width: 45%;
  }
}

Following is an example of using equal height columns to align pairs of products so that the titles are always together on the same line.

Code Complete 5.0

Makes creating .NET applications easier than ever before

Entity, Domain and UI Modelling

Modelling Code Complete Studio enables you to create models that are completely language and technology agnostic. You can choose to start with a model first approach or choose to generate your models from an existing database schema.

T4 Code Based Generation

SoftwareCode Complete comes with a very rich T4 template library. Every component generated by Code Complete is associated with a T4 template that you can modify and customize as you wish. It includes templates for generating the entity and domain layers and different UIs such as ASP.NET MVC and WPF.

Multiple Architectures and ORM Support

Database Code Complete supports generating applications using both single and multiple tiers and the most common data access technologies, including ADO.NET, Entity Framework and NHibernate. Code Complete still provides strong support for CSLA.NET but you can also plug in your own domain framework.

Full Visual Studio Integration

Visual Studios In addition to the a full scale IDE environment for creating your models, Code Complete provides a Visual Studio Add-in that you can use to generate fully working .NET applications based on your models. Code Complete comes with fully customizable templates for C# and VB.NET but you can also plugin your own language.

Getting Started

Video We provide several training videos and tutorials that get you up and running in no time.

Quality resources for our staff.

Trial Download

Download To see how Code Complete can help you improve your productivity, download a free fully functional 20 days trial version.

Read more about fluid and responsive  Layouts.


.