0

I am working on an un-ordered list. I have searched all over the internet for a good tutorial but I cannot find one. I want to display it inline and have a border line in between each <li> item. Now I am just unsure of the standards for styling lists. Do I use padding/margins to position the <li> items? If so do I apply it to the <ul> container or <li> or <a>?

1
  • Welcome to SO. If your question got answered then please accept an answer, otherwise it isn't clear whether you're already satisfied with one of the provided answers. Commented Feb 16, 2012 at 2:19

4 Answers 4

1

Try using margins, borders, and float.

<html>
<head>
<style type="text/css">
.liClass
{
  float:left;
  padding-right:10px;
  padding-left:10px;
  border-right:thick double #ff0000;
}
.lastLi
{
  float:left;
  padding-left:10px;
}
</style>
</head>
<body>
<ul>
<li class="liClass">one</li>
<li class="liClass">two</li>
<li class="lastLi">three</li>
</ul>
</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

why don't you use ul and li in your styling?
@user1174762 - For a couple of reasons. If ul and li are used then it affects a broad range of those html objects, and I may want to use them elsewhere without this style. Also, I can assign class names to my html objects dynamically if I want. Furthermore, using ul and li is actually slower than using class names because css must search the dom for every ul, and then every li.
0

Apply float:left; to <li> and style as needed.

1 Comment

But if i apply it to <li> then the border line overflows out of the <ul> contaner
0

Use display: inline-block to make the list items appear side-by-side (it is more reliable than float: left), then add borders or whatever else you want - maybe a width and some margin.

Comments

0

You can use display: inline-block to avoid having to mess with clearing floats:

http://jsfiddle.net/ZehJN/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.