« back to CSS Swag: Styling Multiple-Column Lists

Method 1: Floating list items

  1. Aloe
  2. Bergamot
  3. Calendula
  4. Damiana
  5. Elderflower
  6. Feverfew
  7. Ginger
  8. Hops
  9. Iris
  10. Juniper
  11. Kava kava
  12. Lavender
  13. Marjoram
  14. Nutmeg
  15. Oregano
  16. Pennyroyal

The above markup should render like this:

Method 1: Floating list items

Notes:

XHTML:

<div class="wrapper">
  <ol
    ><li><a href="#">Aloe</a></li
    ><li><a href="#">Bergamot</a></li
    ><li><a href="#">Calendula</a></li
    ><li><a href="#">Damiana</a></li
    ><li><a href="#">Elderflower</a></li
    ><li><a href="#">Feverfew</a></li
    ><li><a href="#">Ginger</a></li
    ><li><a href="#">Hops</a></li
    ><li><a href="#">Iris</a></li
    ><li><a href="#">Juniper</a></li
    ><li><a href="#">Kava kava</a></li
    ><li><a href="#">Lavender</a></li
    ><li><a href="#">Marjoram</a></li
    ><li><a href="#">Nutmeg</a></li
    ><li><a href="#">Oregano</a></li
    ><li><a href="#">Pennyroyal</a></li
  ></ol>
  <br />
</div><!-- .wrapper -->

CSS:

ol
{
  width: 30em;  /* room for 3 columns */
}
ol li
{
  float: left;
  width: 10em;  /* accommodate the widest item */
}
/* stop the floating after the list */
br
{
  clear: left;
}
/* separate the list from what follows it */
div.wrapper
{
  margin-bottom: 1em;
}
/* anchor styling */
ol li a
{
  display: block;
  width: 7em;
  text-decoration: none;
}
ol li a:hover
{
  color: #FFF; /* white */
  background-color: #A52A2A; /* brown */
}