html - CSS navigation background -


i trying make custom css navigation website have problems can find code sniped bellow. making css vertical navigation here code:

<style type="text/css">  /* gt stylesheet */ #cssmenu > ul { list-style: none; margin: 0; padding: 0; vertical-align: baseline; line-height: 1; }  /* container */ #cssmenu > ul { display: block; position: relative; width: 150px; }  /* list elements contain links */ #cssmenu > ul li {     display: block;     position: relative;     margin: 0;     padding: 0;     width: 250px;    }      /* general link styling */     #cssmenu > ul li {         /* layout */         display: block;         position: relative;         margin: 0;         border-top: 1px dotted #3a3a3a;         border-bottom: 1px dotted #1b1b1b;         padding: 11px 20px;         width: 210px;          /* typography */         font-family: helvetica, arial, sans-serif;         color: #d8d8d8;         text-decoration: none;         text-transform: uppercase;         text-shadow: 0 1px 1px #000;         font-size: 13px;         font-weight: 300;           /* background & effects */         background: #282828;     }      /* rounded corners first link of menu/submenus */     #cssmenu > ul li:first-child>a {         border-top-left-radius: 4px;         border-top-right-radius: 4px;         border-top: 0;     }      /* rounded corners last link of menu/submenus */     #cssmenu > ul li:last-child>a {         border-bottom-left-radius: 4px;         border-bottom-right-radius: 4px;         border-bottom: 0;     }       /* hover state of menu/submenu links */     #cssmenu > ul li>a:hover, #cssmenu > ul li:hover>a {         color: #000;         text-shadow: 0 1px 0 rgba(0, 0, 0, .3);         background: #a9ca6f;         background: -webkit-linear-gradient(bottom, #a9ca6f, #b4d876);         background: -ms-linear-gradient(bottom, #a9ca6f, #b4d876);          background: -moz-linear-gradient(bottom, #a9ca6f, #b4d876);         background: -o-linear-gradient(bottom, #a9ca6f, #b4d876);         border-color: transparent;     }      /* arrow indicating submenu */     #cssmenu > ul .has-sub>a::after {         content: '';         position: absolute;         top: 16px;         right: 10px;         width: 0px;         height: 0px;          /* creating arrow using borders */         border: 4px solid transparent;         border-left: 4px solid #d8d8d8;      }      /* same arrow, darker color, create shadow effect */     #cssmenu > ul .has-sub>a::before {         content: '';         position: absolute;         top: 17px;         right: 10px;         width: 0px;         height: 0px;          /* creating arrow using borders */         border: 4px solid transparent;         border-left: 4px solid #000;     }      /* changing color of arrow on hover */     #cssmenu > ul li>a:hover::after, #cssmenu > ul li:hover>a::after {         border-left: 4px solid #fff;     }      #cssmenu > ul li>a:hover::before, #cssmenu > ul li:hover>a::before {         border-left: 4px solid rgba(0, 0, 0, .3);     } </style> 

the problem cannot make link clicked on change background to: #a9ca6f. want when make <li> id/class active stay color: #a9ca6f help?

thanks in advance!

demo link fiddle!

add this...

#cssmenu li.active {background-color:#a9ca6f;} 

i think need add background-color a , target quite specifically. here's fiddle - i've added line @ bottom of css. if don't target enough won't overrule default style.

edit

to elaborate slightly, in css have stated:

#cssmenu > ul li {...} 

so in order target active class must more specific this, otherwise above rule override others - hence:

#cssmenu > ul li.active {...} 

and not...

li.active  {...} 

so, example, in no-holds-barred fight between css rules...

  1. #menu a beat a.active
  2. a.active beat a
  3. #wrapper #menu a beat #menu a

:-) hth


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -