ปกติผมจะใช้ Skin กำหนด Style ให้กับ Menu, SiteMapPath แล้วไฟล์ Skin ก็จะเรียก Class ใน Css อีกรอบครับ ตัวอย่าง
MenuSkin.skin
<asp:SiteMapPath SkinID="SiteMapPathSkin" runat="server"
CurrentNodeStyle-CssClass="SiteMapPathCurrentNodeStyle"
NodeStyle-CssClass="SiteMapPathNodeStyle"
PathSeparatorStyle-CssClass="SiteMapPathSeparatorStyle"
RootNodeStyle-CssClass="SiteMapPathRootNodeStyle">
</asp:SiteMapPath>
<asp:Menu SkinID="MenuSkin" runat="server"
CssClass="MenuStyle"
DynamicMenuItemStyle-CssClass="DynamicMenuItemStyle"
DynamicHoverStyle-CssClass="DynamicMenuHoverStyle"
DynamicMenuStyle-CssClass="DynamicMenuStyle"
DynamicSelectedStyle-CssClass="DynamicMenuSelectedStyle"
StaticSelectedStyle-CssClass="MenuSelectedStyle"
StaticMenuStyle-CssClass="MenuStyle"
StaticMenuItemStyle-CssClass="MenuItemStyle"
StaticHoverStyle-CssClass="MenuHoverStyle">
</asp:Menu>
NavigationStyles.css
/* ============================================
Menu Style
=============================================== */
.MenuStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
height: 25px;
text-decoration:none;
/*background-color: #FEFEFE;
border: 1px solid #000000;*/
}
.MenuItemStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
padding: 2px 2px 2px 2px!important;
}
.MenuHoverStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
background-color: #9DCE5C;
border: 1px solid #000000;
text-decoration:none!important;
/*background-color: #FFFFCC!important; */
}
.MenuSelectedStyle
{
font-family:Verdana!important;
font-size:8pt!important;
/*background-color:Lime!important;*/
}
/*================================
Dynamic menu Style Section
================================== */
.DynamicMenuStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
padding: 2px 5px 2px 5px!important;
border: 1px solid #000000;
margin-top: -1px;
background-color: #9DCE5C!important;
z-index: 10000;
text-decoration:none;
}
.DynamicMenuItemStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
padding: 2px 2px 2px 2px!important;
border: 1px solid #9DCE5C;
z-index: 10;
text-decoration:none;
/*background-color: #FFCC99!important;*/
}
.DynamicMenuHoverStyle
{
font-family:Verdana!important;
font-size:8pt!important;
color: #000000!important;
background-color: #C7EB6E;
border: 1px solid #000000;
z-index: 10000;
text-decoration:none!important;
/*background-color: #FFFFCC!important; */
}
.DynamicMenuSelectedStyle
{
font-family:Verdana!important;
font-size:8pt!important;
background-image: url(Images/BulletMenu.gif);
z-index: 10000;
/*background-color:Lime!important;*/
}
/* ====================================
SiteMap Style
======================================= */
a.SiteMapPathRootNodeStyle:link,
a.SiteMapPathRootNodeStyle:visited,
a.SiteMapPathRootNodeStyle:active
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: #FFFFFF;
font-weight:bold;
text-decoration:none;
}
a.SiteMapPathRootNodeStyle:hover
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: orange;
font-weight:bold;
text-decoration:none;
}
.SiteMapPathCurrentNodeStyle
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: #FFFFFF;
font-weight:bold;
}
.SiteMapPathNodeStyle
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: #FFFFFF;
font-weight:bold;
}
a.SiteMapPathNodeStyle,
a.SiteMapPathNodeStyle:link,
a.SiteMapPathNodeStyle:visited,
a.SiteMapPathNodeStyle:active
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: #FFFFFF;
font-weight:bold;
text-decoration:none;
}
a.SiteMapPathNodeStyle:hover
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
color: Orange;
font-weight:bold;
text-decoration:none;
}
.SiteMapPathSeparatorStyle
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:8pt;
font-weight:bold;
color: #FFCC33;
}
Apply Skin to Menu and SiteMapPath Web Control
<asp:SiteMapPath ID="SiteMapPath1" runat="server" SkinID="SiteMapPathSkin" SkipLinkText="" PathSeparator=" :: "></asp:SiteMapPath>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" SkinID="MenuSkin" SkipLinkText="" DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2" MaximumDynamicDisplayLevels="5">
<DataBindings>
<asp:MenuItemBinding DataMember="siteMapNode" NavigateUrlField="url" TextField="title" />
</DataBindings>
<DynamicMenuStyle BorderColor="Black" BorderWidth="1px" HorizontalPadding="5px" VerticalPadding="2px" />
</asp:Menu>
ปล. ภายในไฟล์ Css มีการใช้รูปด้วย ซึ่งผมไม่ได้อัพโหลดนะครับ เช่น Class ".DynamicMenuSelectedStyle"
================================
Project Structure
================================
[WebSite Project]
+ App_Theme
- + Forest <== ชื่อ Theme
- - - - MenuSkin.skin <== ไฟล์ skin ของ Menu,SiteMapPath
- - - - NavigationStyles.css <== Css ของ Menu,SiteMapPath
+ MasterPages
- - ContentMasterPage.master
- Default.aspx <== ใช้ ContentMasterPage เป็น master page
- web.config
===================================
กำหนด Default Theme เป็น Forest โดยกำหนดใน Web.Config ดังนี้
<system.web>
<pages theme="Forest" />
</system.web>