简体   繁体   English

菜单控件在环境之间以不同方式构建和呈现

[英]Menu control builds and renders differently between environments

I put the following Menu control on my page: 我在页面上放了以下Menu控件:

<div class="Phase2MenuContainer">
    <asp:Menu runat="server" ID="mnuHome" Orientation="Vertical"
        StaticMenuStyle-CssClass="Phase2Menu">
        <Items>
            <asp:MenuItem Selectable="true" Text="Download Sketch Sheet" NavigateUrl="~/Documents/Sketch Sheet.pdf" Target="_blank"></asp:MenuItem>
            <asp:MenuItem Selectable="true" Text="Create Data Sheet" NavigateUrl="CreateDataSheet.aspx"></asp:MenuItem>
            <asp:MenuItem Selectable="true" Text="Personalize Data" NavigateUrl="Personalize.aspx" Enabled="false"></asp:MenuItem>
        </Items>
    </asp:Menu>
</div>

When I run this on my localhost, it builds with tables which is fine because I knew this when I wrote my css. 当我在我的localhost上运行它时,它使用表构建,这很好,因为我在写css时就知道了。

The problem here is that when I copied it to the live environment, it builds with spans and divs, so all my css broke. 这里的问题是,当我将它复制到实时环境时,它会使用spans和div构建,所以我的所有css都崩溃了。

Here's the css (the live copy just removes the margin: 5px 0; lines) 这是css(实时拷贝只删除margin: 5px 0;行)

.Phase2MenuContainer
{
    width: 250px;
    margin: 15px auto;
}
.Phase2Menu a, .Phase2Menu span a
{
    display: block;
    padding: 10px;
    margin: 5px 0;
    color: #fff;
    height: 30px;
    line-height: 30px;
    width: 200px;
    background: #018CD2;
    border: 1px solid #0159a0;
}
.Phase2Menu a[disabled=true], .Phase2Menu span[disabled=disabled]
{
    display: block;
    padding: 10px;
    margin: 5px 0;
    color: #fff;
    height: 30px;
    line-height: 30px;
    width: 200px;    
    background: #c1c1c1;
    border: 1px solid #0159a0;
}
.Phase2Menu a:not([disabled=true]):hover
{
    background: #3B3486;
}

It took me about half an hour to fix it , but I got it working now (although the live stylesheet is different to my test one). 我花了大约半个小时来修复它,但我现在正在使用它(虽然实时样式表与我的测试样式不同)。

Can anyone explain to me why the menu built differently between my localhost and the live server? 任何人都可以向我解释为什么我的本地主机和实时服务器之间的菜单不同? I'm sure this shouldn't actually happen if it's been done correctly... 我敢肯定,如果做得正确,这实际上不应该发生......

Set the RenderingMode of Menu To Table ..like this. MenuRenderingMode设置为Table ..就像这样。 So it will always render your Menu as table... 因此,它总是将您的Menu呈现为表格...

<asp:Menu runat="server" ID="mnuHome" Orientation="Vertical" RenderingMode="Table"
        StaticMenuStyle-CssClass="Phase2Menu">

I have faced the same solution two days ago and unfortunately, RenderingMode was not working in my project, because of ASP.NET supported version. 我两天前遇到了同样的解决方案,不幸的是,由于ASP.NET支持的版本,RenderingMode无法在我的项目中工作。 Therefore, as a alternative solution, I put menu in div control and set the style sheet as below. 因此,作为替代解决方案,我将菜单放在div控件中并设置样式表如下。

.div br {
    display: none;
}

Hope this may helpful. 希望这可能有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM