Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Guys I'm trying to center this simple ul here. Any idea on whats wrong ?

Css:

ul {
    margin-left: auto;
    margin-right: auto;
}

li {
    display: inline;
    background-color: gray;
    color: white;
    list-style: none;
    margin: 5px;
    padding: 5px;
}

JSP/HTML:

<ul>
        <li>Login</li>
        <li>Option2</li>
        <li>Optino3</li>
    </ul>
share|improve this question
    
First, I think this question would fit better in doctype or stackoverflow. Also it lacks of more description, perhaps a screenshot... –  Dave Dec 10 '10 at 12:11
    
Correct. HTMLCSS questions belong on Doctype as per the FAQ. –  John Conde Dec 10 '10 at 12:58
add comment

closed as off topic by John Conde Dec 10 '10 at 12:57

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Because even though the ul centers (with the margin: auto) it's a block element so it spans the entire width of the element. There is no room for margin on either side of it, you'll have to specify a width for the ul element for this to work.

share|improve this answer
add comment

Check http://matthewjamestaylor.com/blog/2 it has many HTML/CSS articles.

EDIT

Again, nothing against being downvoted. But knowing why downvotes (as well as upvotes, unless it is really really obvious) is important indeed to everyone, including me.

Despite the question best fits in other forum (yeah, I commented on question first), I tried a nice reply as per QA seems to be a beginner. And for beginners, I think the best is not just solve the problem, but learn the basics.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.