Topic: Unordered Lists and Displaying Inline

I have a list I am trying to display inline.
Here is the code.

<ul id="navlist">
<li><a href="javascript: document.cookie='style='; window.location.reload();">Frames</a> <br />
<a href="http://studentorg.ecpi.edu/oswm">By OSWM</a></li>

<li><a href="javascript: document.cookie='style=2'; window.location.reload();">DOS</a><br />
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=3'; window.location.reload();">Gears Of War</a> <br />
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=4'; window.location.reload();">The Greener Side</a><br />
<a href="#">By Shane Jeffers</a></li>

<li><a href="javascript: document.cookie='style=5'; window.location.reload();">Moment of Zen</a><br />
<a href="http://studentweb.ecpi.edu/beachva/mathow7777">By One|Te Productions</a></li>

<li><a href="download/The_Garden.zip">Add To The Garden</a><br />
<a href="#"></a></li>
</ul>


It should have two lines of text for each link, and I want it to be horizontal.

Here is my css for it.

#navlist a {
    color: green;
}

#navlist {
    list-style-type: none;
}

#navlist li{
    display: inline;

}

Thanks for any help.

Vote up Vote down

Re: Unordered Lists and Displaying Inline

Try this:

The HTML:

<ul id="navlist">
<li><a href="javascript: document.cookie='style='; window.location.reload();">Frames</a>
<a href="http://studentorg.ecpi.edu/oswm">By OSWM</a></li>

<li><a href="javascript: document.cookie='style=2'; window.location.reload();">DOS</a>
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=3'; window.location.reload();">Gears Of War</a>
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=4'; window.location.reload();">The Greener Side</a>
<a href="#">By Shane Jeffers</a></li>

<li><a href="javascript: document.cookie='style=5'; window.location.reload();">Moment of Zen</a>
<a href="http://studentweb.ecpi.edu/beachva/mathow7777">By One|Te Productions</a></li>

<li><a href="download/The_Garden.zip">Add To The Garden</a>
<a href="#"></a></li>
</ul>

The only thing I did to the above code is remove the <br /> tags.  Don't need if you set the <a> to display block because you are defining an <a> for each line you want.


The CSS:

#navlist {
    list-style: none;
}
#navlist li {
    display: inline;
    float: left;
}
#navlist li a {
    color: green;
    display: block;
    padding: 3px 15px;
        margin: 0;
}
#navlist li a:hover {
    text-decoration: none;
}

Two important elements here is that I added float: left to the #navlist li and display: block to #navlist a.  Of course I've added a bit of padding/margins to give it a nice look.

Imagine Building and Managing an Online Business
The Kasper Group

Vote up Vote down

Re: Unordered Lists and Displaying Inline

newseed wrote:

Try this:

The HTML:

<ul id="navlist">
<li><a href="javascript: document.cookie='style='; window.location.reload();">Frames</a>
<a href="http://studentorg.ecpi.edu/oswm">By OSWM</a></li>

<li><a href="javascript: document.cookie='style=2'; window.location.reload();">DOS</a>
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=3'; window.location.reload();">Gears Of War</a>
<a href="http://www.richardorobinson.com">By Richard O Robinson</a></li>

<li><a href="javascript: document.cookie='style=4'; window.location.reload();">The Greener Side</a>
<a href="#">By Shane Jeffers</a></li>

<li><a href="javascript: document.cookie='style=5'; window.location.reload();">Moment of Zen</a>
<a href="http://studentweb.ecpi.edu/beachva/mathow7777">By One|Te Productions</a></li>

<li><a href="download/The_Garden.zip">Add To The Garden</a>
<a href="#"></a></li>
</ul>

The only thing I did to the above code is remove the <br /> tags.  Don't need if you set the <a> to display block because you are defining an <a> for each line you want.


The CSS:

#navlist {
    list-style: none;
}
#navlist li {
    display: inline;
    float: left;
}
#navlist li a {
    color: green;
    display: block;
    padding: 3px 15px;
        margin: 0;
}
#navlist li a:hover {
    text-decoration: none;
}

Two important elements here is that I added float: left to the #navlist li and display: block to #navlist a.  Of course I've added a bit of padding/margins to give it a nice look.

You are a life saver my friend.  That also helps me understand CSS a little bit more.  What exactly does display: block do?

Vote up Vote down

Re: Unordered Lists and Displaying Inline

This has a good description, just below the chart at the top of the page:

http://www.quirksmode.org/css/display.html

this might be useful as well:

http://www.w3.org/TR/REC-html40/struct/ … ml#h-7.5.3

Benjamin Falk | Falken Creative : Twitter
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter

Vote up Vote down