: Can't center a ul with css 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;
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>
More posts by @Cooney921
2 Comments
Sorted by latest first Latest Oldest Best
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.
Check 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.