Telerik MVC 菜单控件 - 自动宽度
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Telerik MVC 菜单呈现为
元素。后者默认具有块显示,这意味着它占据了所有可用空间。您可以将显示覆盖为“内联块”,然后菜单应根据需要调整大小:
请记住,旧版本的 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: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.