Centering a css dropdown menu

前端 未结 2 1276
萌比男神i
萌比男神i 2021-01-16 09:21

I\'m trying to center my css dropdown menu, but I can\'t seen to get it to work! I\'ve tried adding text-align: center and margin-left: auto; margin-right: auto, but all tha

相关标签:
2条回答
  • 2021-01-16 09:52

    Since you are using float, the only way to center it is to apply a width to the containing element and use margin-left: auto; margin-right: auto. There is no way to do this will retaining the flexible width.

    An alternative to float would be display:inline-block; These can be centered using text-align:center, but you'll have to rework the css.

    0 讨论(0)
  • 2021-01-16 09:53

    Well, here's one way to do it, you can put a div container around the menu...

    #menuContainer{margin: auto;}

    <div id='menuContainer' style="width: 980px">

    0 讨论(0)
提交回复
热议问题