Reputation:
.list{
list-style: none;
display: inline-block;
text-align: left;
margin:0;
padding:0;
margin-left:-20px;
}
.list > li {
display: inline-block;
width: 100px;
height : 100px;
border: 1px solid black;
margin: 0;
padding: 0;
margin-left: 20px;
margin-bottom: 20px;
}
<div style="text-align:center">
<ul class="list">
<script>
for (var i=0;i<60;i++)
document.write("<li></li>");
</script>
</ul>
</div>
I am trying to make the UL center in the DIV.
Requirements:
Tried these but failed:
Why won't my Div center itself in its parent?
How to horizontally align ul to center of div?
@mark's solution does not work:
Upvotes: 1
Views: 2053
Reputation: 666
Your containing element has to have a width defined; you can't just say text-align: center
for it to work.
Do this:
Essentially you're just defining a few properties on the containing element and took out the margin-left: -20px
. in your code.
Upvotes: 0
Reputation: 67
by default, ul element is like a block, that means it will take 100% width of it's parent. So if you want it to be center, you must set its width to a specific pixel or change the display attribute:
.list{display:inline-block}
Upvotes: 0