Asp.net 4.0 menu 控件样式 + XML 文件配置

本人对WEB UI的设计工作做的很少,多数时间是在后端开发,这个例子做过了,记录下来,以后做个参考

菜单效果如下


菜单上面有鼠标经过的变背景色,和字体加粗变颜色的效果,不方便截图,这里就算了

样式文件 topmenu.css

.staticMenu
{
    background-color: #e4f0ff;
    font-family: Arial;
    display: block;
    font-size: 17px;
    color: #1092E0;
}

.staticMenu:hover
{
    font-weight: bold;
    background-color: #c9e1fd;
    color: #1092E0;
}

.staticMenuItem
{
    background-color: #e4f0ff;
    font-family: Arial;
    font-size: 17px;
    color: #1092E0;
}

.staticMenuItem:hover
{
    font-weight: bold;
}

.dynamicMenu
{
    border-style: solid;
    border-width: 1px;
    font-family: Arial;
    font-size: 12px;
    color: #ffffff;
    background-color: #3582E4;
}

.dynamicMenu:hover
{
    border-style: solid;
    border-width: 1px;
    font-family: Arial;
    font-size: 12px;
    font-weight: bold;
    color: #1092E0 !important;
    background-color: #c9e1fd;
}

dynamicMenu:hover a
{
    background-color: #c9e1fd;
}

.dynamicMenuItem
{
    border-style: solid;
    border-width: 1px;
    font-family: Arial;
    font-size: 12px;
    color: #ffffff;
    background-color: #3582E4;
}

.dynamicMenuItem:hover
{
    border-style: solid;
    border-width: 1px;
    font-family: Arial;
    font-size: 12px;
    font-weight: bold;
    color: #1092E0 !important;
    background-color: #c9e1fd;
}

dynamicMenuItem:hover a
{
    background-color: #c9e1fd;
}

页面代码 

    <div id="menuDiv" style="background: #e4f0ff; width: 100%">
        <asp:Menu ID="menuController" runat="server" DataSourceID="XmlDataSource1" Orientation="Horizontal"
            StaticEnableDefaultPopOutImage="True" StaticTopSeparatorImageUrl="~/Images/spliter.gif"
            IncludeStyleBlock="false">
            <DataBindings>
                <asp:MenuItemBinding DataMember="menuItem" Depth="0" TextField="title" />
                <asp:MenuItemBinding DataMember="subItem" Depth="1" NavigateUrlField="url" TextField="title" />
                <asp:MenuItemBinding DataMember="reportItem" Depth="2" NavigateUrlField="url" TextField="title" />
            </DataBindings>
            <StaticMenuItemStyle CssClass="staticMenu" HorizontalPadding="20px" VerticalPadding="10px" />
            <DynamicMenuItemStyle CssClass="staticMenu" HorizontalPadding="20px" VerticalPadding="5px" />
            <StaticMenuItemStyle CssClass="staticMenuItem" />
            <DynamicMenuStyle CssClass="dynamicMenu" />
            <DynamicMenuItemStyle CssClass="dynamicMenuItem" />
        </asp:Menu>
    </div>
从上面可以看到,菜单项还定义了深度(Depth="xx"),不知道可不可以不设置这项,做成自动递归呈现出来?以后有时间再试吧......

上面的菜单项之间还有个白色的分隔线,其实是一个图片,一个竖长的白色图片,下面是XML的配置菜单(注意拖一个XmlDataSource1控件设置具体的XML文件)

menu.xml

<menu>
  <menuItem title="Reports"  description="">
    <subItem title="Program" url ="">
      <reportItem title="By program" url ="~/byprogram.aspx"/>
      <reportItem title="By Program with Cust Ref" url ="~/byprogramwithcustref.aspx"/>
    </subItem>
    <subItem title ="HM Combos" url ="">
      <reportItem title="H/M Combo" url ="~/hmcombo.aspx"/>
      <reportItem title="H/M Item Combo" url ="~/hmitemcombo.aspx"/>
      <reportItem title="HM Combo Summary" url ="~/hmcombosummary.aspx"/>
    </subItem>
    <subItem title ="Summary" url ="~/summary.aspx"/>
    <subItem title ="Average" url ="~/average.aspx"/>
  </menuItem>
  <menuItem title="I-E Loading Ratio"  description="">
    <subItem title="Internal External Loading Ratio" url ="~/hmieratio.aspx "/>
    <subItem title="I-E Loading Ratio Summary" url ="http://wdmyaxdb/ReportServer/Pages/ReportViewer.aspx?%2fHMLP%2fRpt_Summary"/>
    <subItem title="I-E Loading Ratio Chart" url ="http://wdmyaxdb/ReportServer/Pages/ReportViewer.aspx?%2fHMLP%2fRpt_Summary_Chart"/>
  </menuItem>
</menu>




menu ul li a, .menu ul li a:visited {display:block; text-decoration:none; color:#000;width:150px; height:30px; text-align:center; color:#fff; border-bottom:1px solid #FFF; background:#0069A3; line-height:30px; font-size:14px; overflow:hidden;} .menu ul {padding:0; margin:0;list-style-type: none; } .menu ul li {float:left; margin-right:1px; position:relative;} .menu ul li ul {display: none;} /* specific to non IE browsers */ .menu ul li:hover a {color:#fff; background:#028DE8;}/*一级菜单事件*/ .menu ul li:hover ul {display:block; position:absolute; top:0; left:151px; width:100px;} .menu ul li:hover ul li a.hide {background:#6a3; color:#fff;}/*三级菜单常规*/ .menu ul li:hover ul li:hover a.hide {background:#028DE8; color:#000;}/*三级菜单事件*/ .menu ul li:hover ul li ul {display: none;} .menu ul li:hover ul li a {display:block; background:#028DE8; color:#000;}/*二,三级菜单常规*/ .menu ul li:hover ul li a:hover {background:#6fc; color:#000;}/*二,三级菜单事件*/ .menu ul li:hover ul li:hover ul {display:block; position:absolute; left:151px; top:0; width:100px;} </style> </head> <body> <form id="form1" runat="server"> <div class="menu"> <ul> <li><a class="hide" href="#">城乡规划</a> <ul> <li><a href="#" title="二级菜单1">二级菜单一</a></li> <li><a href="#" title="二级菜单2">二级菜单二</a></li> <li><a href="#" title="二级菜单3">二级菜单三</a></li> <li><a class="hide" href="#" title="这是三级菜单">三级菜单</a> <ul> .................
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值