I'm having trouble spacing a menu control in an ASP.NET page. Is my solution the correct way to do this?
Hey, I added a menu control to my page that is displayed vertically. I couldn't find a way to add spaces (I'd like about 5px.) between the menu items, so I just did something similar to this:
<asp:Menu ID="Menu1" runat="server" BackColor="ActiveBorder">
<Items>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="One" />
</Items>
</asp:Menu>
<p></p>
<asp:Menu ID="Menu2" runat="server" BackColor="ActiveBorder">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Two" />
</Items>
</asp:Menu>
I just created multiple menu 开发者_如何转开发controls with a single menu item control in them, and placed a break between the menu controls. This seems very wrong to me, but I could not figure out another way. Also, this is a bit off subject, but is it okay to use empty paragraph tags as line breaks?(sometimes a br tag is too much) Thanks..
Add the RenderingMode="Table"
property into the Menu.
You should create a class in your CSS file for your menu formatting and assign the margin and/or padding there, then you can assign the class in your menu tag. This will help you avoid using unnecessary markup just for spacing sake.
CSS File:
.menuItem { margin-top:5px;}
aspx markup:
<asp:Menu ID="Menu1" runat="server" CssClass="menuItem" BackColor="ActiveBorder">
<Items>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="One" />
</Items>
</asp:Menu>
My preference would be to use a br tag instead of a p tag, but that may just be my own personal eccentricities... but if you really want to control the spacing, you might want to consider a div between each menu item that has some custom set height. Then you get to choose exactly how far apart each menu item is spaced.
精彩评论