水平无序列表居中,没有固定宽度

时间:2023-01-06 20:24:13

I often want to horizontally center an horizontal menu (an unordered list with the li elements floated) without specifyling a fixed width, so that the menu remains centered in all resolutions.

我经常想要水平居中一个水平菜单(一个无序的列表,其中li元素浮动),而没有指定固定的宽度,因此菜单保持在所有分辨率的中心。

To my knowledge there's no way to achieve that, but perhaps there is some little know trick to achieve it?

据我所知,没有办法实现这一目标,但也许有一些小知识可以实现它?

1 个解决方案

#1


0  

Won't this do the trick?

这不是诀窍吗?

ul{
    list-style:none;
    width:100%;
    text-align:center;
}
li{
    display:inline-block;
}

Fiddle

#1


0  

Won't this do the trick?

这不是诀窍吗?

ul{
    list-style:none;
    width:100%;
    text-align:center;
}
li{
    display:inline-block;
}

Fiddle