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

后端 未结 8 1471
伪装坚强ぢ
伪装坚强ぢ 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:33

    I'm late to this question, but it's really super easy. You just define multiple tab classes in your css file, and then load the required tab as your class in the php file while creating the LI tag.

    Here's an example of doing it entirely on the server:

    CSS

    html ul.tabs li.activeTab1, html ul.tabs li.activeTab1 a:hover, html ul.tabs li.activeTab1 a  { 
        background: #0076B5;
        color: white;
        border-bottom: 1px solid #0076B5;
    }
    
    html ul.tabs li.activeTab2, html ul.tabs li.activeTab2 a:hover, html ul.tabs li.activeTab2 a {
        background: #008C5D;
        color: white;
        border-bottom: 1px solid #008C5D;
    }
    

    PHP

    
    

提交回复
热议问题