【发布时间】:2011-03-10 22:36:51
【问题描述】:
我将有一个导航栏,让用户可以对图片库进行排序。问题是导航栏的宽度会根据画廊的大小而变化,当我没有设置宽度时,我不能使用 margin: 0 auto;使菜单居中。 (相反,每个都显示在画廊容器的左侧。)
这是html:
<div id="nav_container">
<div id="timeline_nav">
<!--<a class="arrow left" />-->
<a class="toggle"/>
<a class="toggle"/>
<a class="toggle"/>
<a class="toggle"/>
<!--<a class="arrow right disabled" />-->
</div>
</div>
还有css:
#nav_container { width:100%;height:20px; position:absolute; bottom:10px; background-color:#000;}
#timeline_nav { position:relative;margin:0 auto; }
#timeline_nav a { display:block; float:left; cursor:pointer; overflow:hidden; }
#timeline_nav a.toggle { width:4px; height:4px; padding:2px; margin:0 2px; background:url(http://images.apple.com/iphone/gallery/images/nav-ticks-20100607.png) 50% 0 no-repeat; }
有什么办法解决这个问题吗?
【问题讨论】:
-
你可以应用 display:inline-block,这会给它一个宽度(它不工作 n ie6 认为).. 如果你使用 javascript 作为画廊,你可以以这种方式居中。
标签: html css navigation nav