如何在DIV标签中对齐asp:Menu?

发布于 2024-09-14 12:13:21 字数 1489 浏览 7 评论 0原文

我的 CSS 看起来像这样:

#menu 
{
 width: 1024px;
 height: 25px;
 margin: 0 auto;
 text-align: right;
 background-color: Red;
}

我的 asp 页面看起来像这样,(片段):

        <asp:Menu ID="mnuMainMenu" runat="server" BackColor="#F7F6F3" 
            DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium" 
            ForeColor="#7C6F57"  
            Orientation="Horizontal" StaticSubMenuIndent="10px" Font-Bold="True">
            <StaticSelectedStyle BackColor="#5D7B9D" />
            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
            <DynamicMenuStyle BackColor="#F7F6F3" />
            <DynamicSelectedStyle BackColor="#5D7B9D" />
            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
            <Items>
                <asp:MenuItem Text="Projekty" Value="Projekty"></asp:MenuItem>
                <asp:MenuItem Text="Licencje" Value="Licencje"></asp:MenuItem>
                <asp:MenuItem Text="Kontrahenci" Value="Kontrahenci"></asp:MenuItem>
            </Items>
        </asp:Menu>

我想让菜单与我的 div 标签的右侧对齐。对齐必须自动完成,如果我添加更多菜单项,菜单应该自行重新对齐。 这在 VS 2008 的分割视图下按预期工作,但在 IE 和 FireFox 中菜单向左对齐。如何解决这个问题?

感谢您抽出时间。

My CSS looks like this:

#menu 
{
 width: 1024px;
 height: 25px;
 margin: 0 auto;
 text-align: right;
 background-color: Red;
}

My asp page looks like this, (in fragment):

        <asp:Menu ID="mnuMainMenu" runat="server" BackColor="#F7F6F3" 
            DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium" 
            ForeColor="#7C6F57"  
            Orientation="Horizontal" StaticSubMenuIndent="10px" Font-Bold="True">
            <StaticSelectedStyle BackColor="#5D7B9D" />
            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
            <DynamicMenuStyle BackColor="#F7F6F3" />
            <DynamicSelectedStyle BackColor="#5D7B9D" />
            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
            <Items>
                <asp:MenuItem Text="Projekty" Value="Projekty"></asp:MenuItem>
                <asp:MenuItem Text="Licencje" Value="Licencje"></asp:MenuItem>
                <asp:MenuItem Text="Kontrahenci" Value="Kontrahenci"></asp:MenuItem>
            </Items>
        </asp:Menu>

I want to have menu aligned to the right side of my div tag. Aligment must be done automaticaly, if I add more menu items menu should realign itself.
This works as expected under split view in VS 2008, however in IE and FireFox the menu is aligned to the left. How to fix this problem?

Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城之時有危險 2024-09-21 12:13:21

您可以将菜单包装在 div 标签中并将其设置为向右浮动,但这使得某些 html 标签也可能浮动到其一侧。

You can wrap the menu in a div tag and set it to float right, this however makes it that certain html tags may float to its side as well.

(り薆情海 2024-09-21 12:13:21

我已将您的代码复制/粘贴到新的网络表单中。
也许这对你有用:
(我在菜单周围的 div 中添加了一个类,并将其浮动到右侧)

<head runat="server">
<title></title>
<style type="text/css"">
#menu 
{
 width: 1024px;
 height: 25px;
 margin: 0 auto;
 text-align: right;
 background-color: Red;
}

#menuContainer{float: right;}

</style></head>

<body><form id="form1" runat="server">
<div id="menuContainer">

<asp:Menu ID="mnuMainMenu" runat="server"  BackColor="#F7F6F3" 
        DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium" 
        ForeColor="#7C6F57"  
        Orientation="Horizontal" StaticSubMenuIndent="10px" Font-Bold="True">
        <StaticSelectedStyle BackColor="#5D7B9D" />
        <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
        <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
        <DynamicMenuStyle BackColor="#F7F6F3" />
        <DynamicSelectedStyle BackColor="#5D7B9D" />
        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
        <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />

        <Items>
            <asp:MenuItem Text="Projekty" Value="Projekty"></asp:MenuItem>
            <asp:MenuItem Text="Licencje" Value="Licencje"></asp:MenuItem>
            <asp:MenuItem Text="Kontrahenci" Value="Kontrahenci"></asp:MenuItem>
        </Items>
    </asp:Menu>
</div>
</form>

I have copied / paste your code into a new webform.
Maybe this will work for you:
(I have added a class to the div around your menu and floated it to the right)

<head runat="server">
<title></title>
<style type="text/css"">
#menu 
{
 width: 1024px;
 height: 25px;
 margin: 0 auto;
 text-align: right;
 background-color: Red;
}

#menuContainer{float: right;}

</style></head>

<body><form id="form1" runat="server">
<div id="menuContainer">

<asp:Menu ID="mnuMainMenu" runat="server"  BackColor="#F7F6F3" 
        DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium" 
        ForeColor="#7C6F57"  
        Orientation="Horizontal" StaticSubMenuIndent="10px" Font-Bold="True">
        <StaticSelectedStyle BackColor="#5D7B9D" />
        <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
        <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
        <DynamicMenuStyle BackColor="#F7F6F3" />
        <DynamicSelectedStyle BackColor="#5D7B9D" />
        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
        <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />

        <Items>
            <asp:MenuItem Text="Projekty" Value="Projekty"></asp:MenuItem>
            <asp:MenuItem Text="Licencje" Value="Licencje"></asp:MenuItem>
            <asp:MenuItem Text="Kontrahenci" Value="Kontrahenci"></asp:MenuItem>
        </Items>
    </asp:Menu>
</div>
</form>

楠木可依 2024-09-21 12:13:21

这是一个旧线程,但当前执行此操作的方法是在菜单本身的“Properties”中,只需放入 StaticMenuStyle-CssClass="menu" 并使用与上面相同的CSS样式。

This is an old thread, but the current way of doing this is in the "Properties" of the Menu itself, just put in StaticMenuStyle-CssClass="menu" and use the same css style as above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文