Telerik MVC 菜单控件 - 自动宽度

发布于 2024-12-03 13:24:22 字数 1115 浏览 1 评论 0原文

我正在尝试使用 Telerik MVC 菜单控件(作为按钮栏),但似乎无法将宽度设置为自动生成。我的意思是,菜单一直持续到 DIV 的末尾。我希望菜单的宽度仅与按钮宽度的总和一样宽。实际上,Telerik 演示正在执行与我的菜单相同的操作:

http:// /demos.telerik.com/aspnet-mvc/razor/menu/sitemapbinding (看看菜单如何继续到“其他产品线”的右侧)。

这是我的菜单:

    @{ Html.Telerik().Menu()
            .Name("case-history-button-menu")
            .ClientEvents(events => events.OnSelect("onCaseHistoryMenuBarSelect"))
            .Items(menu =>
            {
                menu.Add()
                    .Text("Add a Response").HtmlAttributes(new { id = "cases-history-addresponse" } ); @*Sets the ID HTML attribute so we can access it *@
                menu.Add()
                    .Text("Add a Comment").HtmlAttributes(new { id = "cases-history-button-addcomment" }); ;
                menu.Add()
                    .Text("Back to Cases").HtmlAttributes(new { id = "cases-history-button-back" }); ;
            })
            .Render();
    }

我确实意识到我可以对宽度进行硬编码......但是当我添加或删除按钮(以编程方式)时,我希望调整菜单大小。

I am trying to use the Telerik MVC Menu control (as a button bar), but can't seem to be able to set the width to auto-generate. What I mean is, the menu continues to the end of the DIV. I would like the menu to only be as wide as the sum of the button widths. Actually, the Telerik demo is doing the same thing as my menu is doing:

http://demos.telerik.com/aspnet-mvc/razor/menu/sitemapbinding
(Look at how the menu continues on to the right of "Other product lines").

Here is my menu:

    @{ Html.Telerik().Menu()
            .Name("case-history-button-menu")
            .ClientEvents(events => events.OnSelect("onCaseHistoryMenuBarSelect"))
            .Items(menu =>
            {
                menu.Add()
                    .Text("Add a Response").HtmlAttributes(new { id = "cases-history-addresponse" } ); @*Sets the ID HTML attribute so we can access it *@
                menu.Add()
                    .Text("Add a Comment").HtmlAttributes(new { id = "cases-history-button-addcomment" }); ;
                menu.Add()
                    .Text("Back to Cases").HtmlAttributes(new { id = "cases-history-button-back" }); ;
            })
            .Render();
    }

I do realize that I could just hard code my width ... but as I add or remove buttons (programatically) I want the menu to resize.

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

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

发布评论

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

评论(1

幻梦 2024-12-10 13:24:22

Telerik MVC 菜单呈现为

    元素。后者默认具有块显示,这意味着它占据了所有可用空间。您可以将显示覆盖为“内联块”,然后菜单应根据需要调整大小:

   @{ Html.Telerik().Menu()
            .Name("case-history-button-menu")
            // set the display to inline-block
            .HtmlAttributes( new { style = "display: inline-block" } )
    }

请记住,旧版本的 IE 不接受内联块显示。如果您必须支持较旧的 IE,则可能需要“内联”。

The Telerik MVC menu is rendered as an <UL> element. The latter has block display by default which means it occupies all the available space. You can override the display to "inline-block" and then the menu should be sized as you need it to:

   @{ Html.Telerik().Menu()
            .Name("case-history-button-menu")
            // set the display to inline-block
            .HtmlAttributes( new { style = "display: inline-block" } )
    }

Have in mind though that older versions of IE won't accept inline-block display. You may need "inline" if you must support older IEs.

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