如何在Umbraco水平显示子菜单?

时间:2015-06-05 11:09:43

标签: css menu umbraco

我需要在主导航中按水平顺序显示子导航菜单。我可以在垂直方向显示子导航,但我不知道如何在水平方向上更改它。

我使用以下代码显示:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{ var home = CurrentPage.Site(); }
@if (home.Children.Any())
{
    @* Get the first page in the children *@
    var naviLevel = home.Children.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="level-@naviLevel" >            
        @* For each child page under the home node *@
        @foreach (var childPage in home.Children)
        {   
            if (childPage.Children.Any())
            {                    
                <li  style="width:14%;text-align:left; "class="has-child  @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)" >
                    @if(childPage.DocumentTypeAlias == "LandingPage") 
                    {
                        <a style="padding-left:inherit;font-size:11px;" href="@childPage.Url">@childPage.Name</a>
                        @childPages(childPage.Children)
                    } else {
                        <a style="padding-left:inherit;font-size:11px;" href="@childPage.Url">@childPage.Name</a>
                    }
                </li>
            } 
            else
            {
                <li style="width:14%;padding-right:15px;text-align:left;" class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                    <a  style="font-size:11px;padding-left:inherit;" href="@childPage.Url">@childPage.Name</a>
                </li>
            }            
        }

    </ul>

}

@helper childPages(dynamic pages)
{
    @* Ensure that we have a collection of pages *@
    if (pages.Any())
    {
        @* Get the first page in pages and get the level *@
        var naviLevel = pages.First().Level;

        @* Add in level for a CSS hook    class="sublevel level-@(naviLevel)" style="background-color:white;" *@

        <ul class="sublevel level-@(naviLevel)" style="background-color:white;position:fixed; top:150px;margin-left: 520px;width: 873px;">
            @foreach (var page in pages)
            {
              <li>
                    <a  href="@page.Url" style="font-size:12px;color:black;">@page.Name<span style="float:right;color:#FF6900;padding: 0px;margin-top: -26px;">></span></a>
                  @*  <input  src="/media/1095/site-search-image-button.png" style="height:22px;width:21px;float:right" type="image">>*@
                    @* if the current page has any children *@
                    @if (page.Children.Any())
                    {                        
                        @* Call our helper to display the children *@
                        @childPages(page.Children)
                    }
                    </li>

            }
        </ul>

    }
}

1 个答案:

答案 0 :(得分:1)

首先,这是相当可怕的,但由于您已经在使用内联样式,请添加

<li style="display:inline"> 

到下面的部分

<ul class="sublevel level-@(naviLevel)" style="background-color:white;position:fixed; top:150px;margin-left: 520px;width: 873px;">
            @foreach (var page in pages)
            {
              <li style="display:inline"> 
                    <a  href="@page.Url" style="font-size:12px;color:black;">@page.Name<span style="float:right;color:#FF6900;padding: 0px;margin-top: -26px;">></span></a>
                  @*  <input  src="/media/1095/site-search-image-button.png" style="height:22px;width:21px;float:right" type="image">>*@
                    @* if the current page has any children *@
                    @if (page.Children.Any())
                    {                        
                        @* Call our helper to display the children *@
                        @childPages(page.Children)
                    }
                    </li>

            }
        </ul>