本人对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>