How to dynamically change the color of the selected menu item of a web page?

后端 未结 8 1482
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 14:55

I am new to developing web pages. I am looking to create menus similar to the ones in stackoverflow.com (like Questions, Tags, Users shown above). How do I change the color

8条回答
  •  死守一世寂寞
    2020-12-13 15:35

    It would probably be easiest to implement this using JavaScript ... Here's a JQuery script to demo ... As the others mentioned ... we have a class named 'active' to indicate the active tab - NOT the pseudo-class ':active.' We could have just as easily named it anything though ... selected, current, etc., etc.

    /* CSS */
    
    #nav { width:480px;margin:1em auto;}
    
    #nav ul {margin:1em auto; padding:0; font:1em "Arial Black",sans-serif; }
    
    #nav ul li{display:inline;} 
    
    #nav ul li a{text-decoration:none; margin:0; padding:.25em 25px; background:#666; color:#ffffff;} 
    
    #nav ul li a:hover{background:#ff9900; color:#ffffff;} 
    
    #nav ul li a.active {background:#ff9900; color:#ffffff;} 
    
    /* JQuery Example */
    
    
    
     /* HTML */
    
    
    

提交回复
热议问题