XML technologies / CSS / Advanced websites with CSS / Fixed-width layouts / Fixed-width multicolumn layouts / Floating columns

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

There are several reasons to prefer floating columns to absolute positioning here. You may want a footer always below every column, which floats handle easily, or want page content to flow around the floating column instead of staying within its own column’s width. Floats allow that too.

If you choose to move the sidebar with float, place the element div with ID #extras immediately before the tag <div id="content-wrapper"> in the document.

<div id="main">
  <div id="extras">
   ...
  </div> <!-- extras -->
  <div id="content-wrapper">

To float this column to the side, replace the positioning declarations in the CSS rule for #extras with the declaration float: left. The next figure shows the effect:

#extras {
  float: left;
  width: 180px;
  background-color: white;
  border: 1px solid #f0f0f0;
}

The floating column appears as expected in Firefox

Figure: The floating column appears as expected in Firefox.

That single change places the sidebar to the left of the main area in Firefox. Internet Explorer, however, causes more trouble, as the following figure shows.

Internet Explorer 6 hides the World Cup logo and pushes the tournament schedule below the sidebar

Figure: Internet Explorer 6 hides the World Cup logo and pushes the tournament schedule below the sidebar.

The World Cup logo has disappeared and the schedule sits below the sidebar’s bottom. Testing in Internet Explorer 6 often reveals CSS bugs. Most were fixed in version 7, but unfortunately it will take time before most users upgrade and version 6 can be ignored.

These bugs usually stem from Internet Explorer’s “having layout” concept, explained in the article “On Having Layout”. A simple workaround assigns one of several declarations to a parent of the problematic element. Here, applying display: inline-block (Note: theoretically this changes the behavior of #content when adjacent to other elements. In this case, nested within the element #content-wrapper, it has no effect.) to the element div with ID #content solves the problem, as the next figure shows.

#content {
  background-color: white;
  border: 1px solid #f0f0f0;
  padding: 0;
  display: inline-block;
}

The article “On Having Layout” lists the suitable properties and discusses their side effects.

The floating column now also works in Internet Explorer 6

Figure: The floating column now also works in Internet Explorer 6.

These examples show how flexible CSS layouts can be. Instead of rebuilding nested table layouts from scratch, a few new CSS rules can make major changes.

  

 

 

 

back to top