04 Beyond Floats

Sitepoint released a spot on article, Give Floats the Flick in CSS Layouts that goes over alternate strategies to lay out a page, mostly relying on the display property to change the display of an element from a list item to an inline-block, for example.

Possible display modes are: inline, block, list-item, run-in, inline-block, table, inline-table, table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, table-caption, none and inherit.

The markup for these examples look like this except as noted:

<nav>
	<ul>
		<li><a href="#">menu 1</a>
		<li><a href="#">menu 2</a>
		<li><a href="#">menu 3</a>
		<li><a href="#">menu 4</a>
		<li><a href="#">menu 5</a>
	</ul>
</nav>

Display Inline-Block

Inline-block displays block level elements into inline level elements with block attributes like margins, padding, width, height, and vertical-align, attributes that inline elements do not have. It’s incredibly useful in any situation where you want to align block elements horizontally in rows, as they can be aligned by the top, middle or bottom.

CSS Code View

Each line items can be more than just a menu item, which is what this property is often asked to do. The boxes can be aligned from the top, center or bottom, and can contain all kinds of objects to serve as a layout strategy. If your page were designed to contain a number of columns, this is one way to lay out that page.

Using Margins to Space Columns

By using a large margin to move the main body copy to the right, and using absolute positioning to place the content of the first column, you have a two columns page layout.

The markup for the 2 column layout looks like this:

<article>
	<p>… main content here
</article>
<nav>
	<ul>
		<li><a href="#">menu 1</a>
		<li><a href="#">menu 2</a>
		<li><a href="#">menu 3</a>
		<li><a href="#">menu 4</a>
		<li><a href="#">menu 5</a>
	</ul>
<nav>

CSS Code View

… main content here.

Display Tables

Without using tables, of course. Apply the layout behavior of tables, rows and cells to any HTML element. For alignment into columns or rows, these display values are a quick and easy solution, harkening back when tables were the ubiquitous layout strategy, but unlike tables, this is legal.

CSS Code View

This can be used to create multiple column layouts.

CSS Code View

  • Bubble bath

    A wet foam—such as that on a cappuccino—and a trough of plastic beads are both made up of nearly spherical, close-packed objects, but do these two types of materials, which are neither fully liquid or solid like, have anything in common? Experiments presented in Physical Review Letters suggest similarities between foams and granular matter that may lead to a more unified theory for describing the two materials.

  • In a tight spot, spin and charge separate

    Strange things happen when there is a shortage of space. The Pauli exclusion principle is well known for its effect on fermions, but bosons (for instance, photons) also behave interestingly when pressed for space. For this reason, researchers are very interested in schemes that create this kind of environment, in search of new physics and new technologies.

  • Reading a single spin in silicon

    The holy grail of research in quantum computing is to simultaneously meet the DiVincenzo criteria—five obstacles that must be overcome to transform a quantum system into a scalable quantum computer [1]. Overcoming the first two, namely to have well-characterized qubits and long decoherence times can be a simple matter: Nature provides a variety of long-lived quantum systems.

Vertically Centering a Box

It is almost impossible to vertically center an object unless you turn it into a table cell and assign it a vertical alignment of center. It could just as well be top or bottom, of course:

The markup for the centered example looks like this:

<div id="centered">
	<div>
<div>
	

Vertically and horizontally centered </div> </div> </div>

CSS Code View

Vertically and horizontally centered

These page layout solutions do not rely on the ubiquitous float. The time will come when the W3 Grid Layout module is adopted, and the landscape changes, but these techniques will not go away. Instead, use them where they fit, anywhere you need to layout out your document.