How to style an asp.net menu with CSS

前端 未结 11 1250
囚心锁ツ
囚心锁ツ 2020-11-30 00:36

I\'m in the process of styling an asp.net menu and I\'m trying to understand the meaning of the StaticSelectedStyle-CssClass and StaticHoverStyle-CssClass parameters.

<
11条回答
  •  鱼传尺愫
    2020-11-30 01:20

    I remember the StaticSelectedStyle-CssClass attribute used to work in ASP.NET 2.0. And in .NET 4.0 if you change the Menu control's RenderingMode attribute "Table" (thus making it render the menu as s and sub-s like it did back '05) it will at least write your specified StaticSelectedStyle-CssClass into the proper html element.

    That may be enough for you page to work like you want. However my work-around for the selected menu item in ASP 4.0 (when leaving RenderingMode to its default), is to mimic the control's generated "selected" CSS class but give mine the "!important" CSS declaration so my styles take precedence where needed.

    For instance by default the Menu control renders an "li" element and child "a" for each menu item and the selected menu item's "a" element will contain class="selected" (among other control generated CSS class names including "static" if its a static menu item), therefore I add my own selector to the page (or in a separate stylesheet file) for "static" and "selected" "a" tags like so:

    a.selected.static
    {
    background-color: #f5f5f5 !important;
    border-top: Red 1px solid !important;
    border-left: Red 1px solid !important;
    border-right: Red 1px solid !important;
    } 
    

提交回复
热议问题