代码之家  ›  专栏  ›  技术社区  ›  Richard Slater

在ASP.net中是否有一种优雅的方法来实现可选选项卡/菜单

  •  1
  • Richard Slater  · 技术社区  · 16 年前

    1. 每次页面加载时动态生成HTML

    这些似乎都不太优雅,我觉得在ASP.net中有更好的方法来做到这一点,但我不知道我在寻找(或搜索)什么。

    <div id="tabs">
        <ul>
            <li class="selectedtab"><a href="/">Courses</a></li>
            <li><a href="#">My Courses</a></li>
            <li><a href="#">Administration</a></li>
        </ul>
    </div>
    

    #head ul 
    {
        list-style: none;
        padding:0;
        margin:0;
    }
    
    #head li 
    {
        display: inline;
        border: solid;
        border-width: 1px 1px 0 1px;
        margin: 0 0.5em 0 0;
        background: #EEE;
        font-size: large;
        font-weight: bold;
        padding-top: 0.3em;
    }
    
    #head li a 
    {
        padding: 0 1em;
        text-decoration: none;
        color: Black;
    }
    
    #head .selectedtab
    {
        padding-bottom: 1px; 
        background: white;
        border-bottom: 1px solid white;
    }
    
    #tabs
    {
        text-align: right;
        width: 100%;
        border-bottom: 1px solid;
    }
    
    2 回复  |  直到 16 年前
        1
  •  1
  •   Cerebrus    16 年前

    <!-- the tabs now have a class you can use -->
    <div id="tabs">
        <ul>
            <li class="tabone"><a href="/">Courses</a></li>
            <li class="tabtwo"><a href="#">My Courses</a></li>
            <li class="tabtre"><a href="#">Administration</a></li>
        </ul>
    </div>
    

    <body class="tabonepage">...
    

    第二页

    <body class="tabtwopage">...
    

    .tabonepage .tabone,
    .tabtwopage .tabtwo,
    .tabtrepage .tabtre,
    {
        padding-bottom: 1px; 
        background: white;
        border-bottom: 1px solid white;
    }
    

    编辑

    主控。大师:

    <body class='<%=BodyClass%>'>
    

    主控。Master.cs

    public string BodyClass{ get; set; }
    

    所有其他页面

    <%@ MasterType VirtualPath="~/MasterPages/MainMaster.Master" %>
    

    所有其他页面

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.Master.BodyClass = "areamydetails";
        }
    
        2
  •  1
  •   Dan F    16 年前

    我认为根据当前位置切换DIV或控件的CSS类是一种相当优雅的方式。NET导航API(使用网站地图),你应该做得很好!