Horizontal List that wraps without overlapping


I’m trying to create a list (UL) which is displayed horizontally. Each item has some padding around it. The problem I’m having is that when the list gets to the end of the line and starts wrapping to the next line, it doesn’t render low enough and starts overlapping the first line. Can someone help me figure out how to get the wrapping to go on to the next line without overlapping?

Here’s the CSS

.letterlist ul {
   margin: 0; padding: 0; 
    list-style-type: none; list-style-image: none;

.letterlist li 

.letterlist li a
    margin: 4px;
    padding: 10px 20px;
    font-weight: bold;
    border-radius: 5px;

Here’s the HTML

<ul class="letterlist">
    <li><a href="/list/A">A</a></li>
    <li><a href="/list/B">B</a></li>
    <li><a href="/list/C">C</a></li>
    <li><a href="/list/D">D</a></li>
    <li><a href="/list/E">E</a></li>
    <li><a href="/list/F">F</a></li>
    <li><a href="/list/G">G</a></li>
    <li><a href="/list/H">H</a></li>
    <li><a href="/list/I">I</a></li>
    <li><a href="/list/J">J</a></li>
    <li><a href="/list/K">K</a></li>
    <li><a href="/list/L">L</a></li>
    <li><a href="/list/M">M</a></li>
    <li><a href="/list/N">N</a></li>
    <li><a href="/list/O">O</a></li>
    <li><a href="/list/P">P</a></li>
    <li><a href="/list/Q">Q</a></li>
    <li><a href="/list/R">R</a></li>
    <li><a href="/list/S">S</a></li>
    <li><a href="/list/T">T</a></li>
    <li><a href="/list/U">U</a></li>
    <li><a href="/list/V">V</a></li>
    <li><a href="/list/W">W</a></li>
    <li><a href="/list/X">X</a></li>
    <li><a href="/list/Y">Y</a></li>
    <li><a href="/list/Z">Z</a></li>

I’m using blueprint CSS if that matters.


You can either float all the li elements or give them display: inline-block, then give them some top and bottom margin:

.letterlist li {
    float: left; 
       /* or */ 
    display: inline-block;

    margin: 20px 0;

See: http://www.jsfiddle.net/yijiang/z8Gfe/ for a simple example. And by the way, ul elements are not valid in p paragraphs

Answered By – Yi Jiang

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.