CSS keeping parent rules instead of class -


in situation:

<ul id="menu_pages">                       <li class="menu_pages_title">                         <div id="menu_pages_container">                             <a href="#">aaa</a>                             <div class="page_content">                              <div class="page_content_actions">                                     <a class="edit" href="#">bbb</a>                             </div>                                 test 1                             </div>                         </div>                     </li>  </ul>  ul#menu_pages li{     margin-bottom: 10px; }      ul#menu_pages li a:link,ul#menu_pages li a:active,ul#menu_pages li a:visited{         display:block;         padding:5px;         border:1px solid #c3d5df;         line-height:25px;         font-size: 15px;         font-weight: bold;         color:#c3d5df;  }  div.page_content_actions li a.edit:link, div.page_content_actions a.edit:active, div.page_content_actions a.edit:visited {                     background: url('/site_images/page_edit.png') left no-repeat;                     display:block;                     padding:0;                     border:0;                     font-size: 11px;                     font-weight: bold;                     color:#fff;                  } 

the .edit class should own rules set (inside .page_content_actions) instead .edit getting background, rest coming general #menu_pages li a. why that?

css follows specificity rules, means if have 2 classes might both apply, weighed out , more specific 1 applied. see excellent article more in-depth explanation:

http://htmldog.com/guides/cssadvanced/specificity/

in case, #menu_pages li a has specificity of 102 (100 id selector , 1+1 2 html element selectors) while a.edit has specificity of 11 (10 class selector , 1 html selector). either reduce specificity of first or increase specificity of second achieve desired effect.

additionally, use !important @ end of rule want override rule higher specificity. note must applied each style individually.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -