html ul在div里居中,在DIV内水平居中UL

我的div里面有ul,我希望将ul水平放在屏幕的中心位置。

可以在此处找到项目的完整代码:jsfiddle

我尝试过使用:

margin: 0 auto; /* After setting the width of course */

text-align: center; /* Ran out of ideas!! */

我也尝试过相对定位和设置%而不是px,但这并没有给我准确的屏幕中心,而且,如果我在菜单中添加了更多项目,那么在包含它们之后它就不会是中心(使用一个 %)。

我的完整代码位于jsfiddle,供您修改。

为方便起见,我贴了一些(我认为的)相关代码:

CSS:

/* Main*/

ul#nav {

display: inline-block;

padding: 0px;

list-style-type: none;

white-space: nowrap;

position: relative;

top: 10px;

left: 10%; /* This is what im currently using, but as thought, it doesnt work as needed :(*/

border: 2px solid chocolate;

-moz-border-radius: 10px; /* Border Radius for Mozilla Firefox */

border-radius: 10px; /* Border Radius for everything else*/

}

ul#nav li {

float: left;

font-family: 'Myraid Pro', Arial, Helvetica, sans-serif; /*Use available font for menu */

font-weight: bold;

margin: 0;

padding: 5px 0 4px 0;

background-color: #ee8043; /*Background Colour for the

*/

padding: 5px; /* Padding for the LI */

-moz-border-radius: 8px; /* Border Radius for Mozilla Firefox */

border-radius: 8px; /* Border Radius for everything else*/

}

HTML:

基本上,我想将#nav包含在#navbar中,#navbar包含在#header中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值