如何水平对齐ul到div的中心? [英] How to horizontally align ul to center of div?
本文介绍了如何水平对齐ul到div的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将< ul>
置于< div>
我尝试了以下操作:
text-align:center;
和
left:50%;
这不起作用。
strong> CSS :
.container {
clear:both;
width:800px;
height:70px;
margin-bottom:10px;
text-align:center;
}
.container ul {
padding:0 0 0 20px;
margin:0;
list-style:none;
}
.container ul li {
margin:0;
padding:0;
}
我想要 ul
IE7 +: max-width:660px
和 margin:auto
您可以通过指定固定宽度和边距-right和-left设置为自动。
.container ul {
/ width`而不是`max-width` * /
max-width:660px;
margin-right:auto;
}
注意:
- 不需要容器
I am trying to center a
<ul>
inside a<div>
. I tried the followingtext-align: center;
and
left: 50%;
This is not working.
CSS:
.container { clear: both; width: 800px; height: 70px; margin-bottom: 10px; text-align: center; } .container ul { padding: 0 0 0 20px; margin: 0; list-style: none; } .container ul li { margin: 0; padding: 0; }
I want the
ul
to be centered inside the container.解决方案IE7+:
max-width: 660px
andmargin: auto
You can center a block-level element by assigning a fixed width and margin-right and -left set to auto.
.container ul { /* for IE below version 7 use `width` instead of `max-width` */ max-width: 660px; margin-right: auto; }
Notes:
- No container needed
这篇关于如何水平对齐ul到div的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- No container needed
查看全文