简体   繁体   English

ASP:菜单子项保持可见

[英]ASP:Menu children stays visible

First of all, I want to say that I still think this site has the best answers. 首先,我想说的是,我仍然认为该站点具有最佳答案。 Helped me a lot throughout this year. 全年对我有很大帮助。 Basically, I have looked everywhere but have come up empty. 基本上,我到处都看过,但空虚了。

Ok, so I will try and keep this as simple as I can: 好的,所以我将尽量保持简单:

  1. I have an ASP:Menu that retrieves it data from the database. 我有一个ASP:Menu,可以从数据库中检索数据。 This includes its parents and children linked with id's. 这包括与ID关联的父母和子女。
  2. This is then added into a recursive method that creates the menu items, adding children to the correct parents. 然后将其添加到创建菜单项的递归方法中,从而将子级添加到正确的父级中。 - Still fine here. -还是不错。 Works perfectly. 完美运作。
  3. It then goes through to populate the asp:menu control that I have inserted on my web page. 然后,它将填充我在网页上插入的asp:menu控件。 - Still fine here as well. -这里也很好。
  4. Then after the items have been added, the asp:menu displays it beautifully I might add. 然后,在添加项目之后,asp:菜单会以精美的方式显示它,我可能会添加它。 So I'm still fine here as well. 所以我在这里也很好。

The next part is what is the main issue: 下一部分是主要问题:

After 3 agonizing days, I've tried to do the most simplest thing but to absolutely no avail: Displaying all of the children items of the parents (meaning ALL of the parents' children) WITHOUT hovering over the parents AND without using Javascript. 经过3天的苦苦挣扎,我尝试做最简单的事情,但绝对无济于事:显示父母的所有孩子项目(意味着所有父母的孩子),而无需将鼠标悬停在父母身上并且不使用Javascript。 Only pure CSS and HTML along with the C# for the code behind the ASP.Net. ASP.Net背后的代码只有纯CSS和HTML以及C#。

I want something like the following: 我想要以下内容:

  • From something like: 从类似:

    nav > ul > li:hover > div{ display: block; opacity: 1; visibility: visible; }

  • To

    nav > ul > li > div{ display: block; opacity: 1; visibility: visible; }

The sample code above basically means that no hover is needed over the parent items in order to display the children. 上面的示例代码基本上意味着不需要悬停在父项上即可显示子项。 So, in a nutshell, I need something similar for my asp:menu parents and children. 因此,简而言之,我的asp需要一些类似的东西:菜单父母和孩子。 I only have 1 level of children. 我只有1个等级的孩子。 This means that my children doesn't have children. 这意味着我的孩子没有孩子。 1 parent with multiple children and that is it. 1个父母有多个孩子,就是这样。 Then it goes over to the other parents and children. 然后,它传给其他父母和孩子。

The following is an example of the data structure that I have: 以下是我拥有的数据结构的示例:

  • Company 公司

    |--- About Us | ---关于我们

    |--- Services | ---服务

    |--- Presentation | ---介绍

    |--- Clients | ---客户

  • Products 产品展示

    |--- Commercial | ---商业

    |--- Residential | ---住宅

This is the code for the asp:menu that I have: 这是我拥有的asp:menu的代码:

<asp:Menu ID="uxLiteral1" Orientation="Horizontal" runat="server"
OnMenuItemClick="Bottom_Click" SkipLinkText=""
StaticEnableDefaultPopOutImage="False" IncludeStyleBlock="False"/>

As I understand, this can be done with CSS, but at this point, I will take anything I can. 据我了解,这可以使用CSS来完成,但是在这一点上,我将尽一切可能。

I apologize for the long post, and thank you so much in advance!! 我为冗长的帖子表示歉意,并在此先感谢您!!

PS: I have already looked at the StaticDisplayLevels property and that doesn't add it underneath each other. PS:我已经看过StaticDisplayLevels属性,并且没有将其添加到彼此之间。 So that won't work for me. 所以这对我不起作用。 I am open to use any other controls to get the job done. 我愿意使用任何其他控件来完成工作。

EDIT : Here is the CSS code that I have found the asp:menu generates itself with the code that should supposedly display the items the menu houses, but currently it just doesn't seem to work. 编辑 :这是我发现asp:menu生成的CSS代码,应该使用应该显示菜单所包含项目的代码来生成自身,但是目前看来似乎不起作用。

.FooterDetails > .Square > #BotMenu1_UpdatePanel1 > #BotMenu1_uxLiteral1 > ul.static { font-weight: bold; }

.FooterDetails > .Square > #BotMenu1_UpdatePanel1 > #BotMenu1_uxLiteral1 > ul.static > li.static > ul.dynamic > li.dynamic > a.dynamic { font-weight: normal; visibility: visible !important; padding-right: 25px; margin-bottom: 3px; }

The static class is the first item, ie the Header for my items and also the parent. 静态类是第一个项目,即我的项目的标题和父项。 In this case it would be the "Company" and "Products". 在这种情况下,它将是“公司”和“产品”。

The dynamic class is the children the static class houses. 动态班级是静态班级的孩子。

Well after another day of struggling to figure this one out, the answer appears to be simple enough. 经过努力解决这一问题的第二天,答案似乎很简单。

Giving the asp:menu a new css class like so: 给asp:menu一个新的CSS类,如下所示:

<asp:Menu ID="uxLiteral1" runat="server" CssClass="FooterMenu" Orientation="Horizontal"     IncludeStyleBlock="false" StaticEnableDefaultPopOutImage="False"     OnMenuItemClick="NavigationMenu_MenuItemClick" DisappearAfter="0" />

The CSS would then be changed so that the menu and all of its items become linked to only the following CSS: 然后将更改CSS,以便菜单及其所有项目仅链接到以下CSS:

div.FooterMenu
{
    align-content: center !important;
}

div.FooterMenu ul
{
    list-style: none;
    display: inline-block !important;
}

    div.FooterMenu ul li
    {
        padding-right: 65px;
        margin-bottom: 3px;
    }

This would give you the desired effect of displaying all of the child items per parent without any hover effect. 这将为您提供显示每个父项的所有子项而没有任何悬停效果的理想效果。 Again, I feel like da real MVP. 同样,我觉得自己是真正的MVP。

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

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