asp.netcssaspmenu-control

Centering asp:menu item's when there are multiple rows of menu items


you can replicate my problem with this small code snippet.

    <div ID="topcell" runat="server" align="center" style="text-align:center">
   <asp:Menu ID="testmenu" runat="server" Width="300px" Orientation="Horizontal" RenderingMode="List">

    <Items>
    <asp:MenuItem Text="Testing"></asp:MenuItem>
    <asp:MenuItem Text="Testing"></asp:MenuItem>
    <asp:MenuItem Text="Testing"></asp:MenuItem>
    <asp:MenuItem Text="Testing"></asp:MenuItem>
    <asp:MenuItem Text="Testing"></asp:MenuItem>
    <asp:MenuItem Text="Testing"></asp:MenuItem>



    </Items>
   </asp:Menu>
   </div>

Result:

Desired results:

I have tried all three RenderingModes with no luck! Am I doing something wrong?


Solution

  • Try adding following CSS to your page:

    <style type="text/css" >
       #testmenu ul li {
          display:inline-block;
          float:none !important;
       }
    </style>  
    

    It will overwrite inline menu styles and force the unordered list to center.