x-y-z-select
x-y-z-select

Reputation: 95

CSS id inside class

My menu with jquery changing classes when scrolling. When you scroll up class is menugore and when you go back class is menudole. I want the buttons to be different in each class. When you are up, to stay this like now and when they come back to be background-image: url ('..');

Here is code of my one button:

li#menu-item-631 a{
    display: inline-block;
    width:90px;
    height:15px;
    padding:15px;
    margin-left:37px;
    line-height: 15px; 
    font-size: 24px;
    color: white; 
    margin-left: 40px;
    text-decoration:none;
    text-align: center;
    background: #014464;
    background: -moz-linear-gradient(top, #0D658E, #0C577A 50%, #014D71 51%, #003E5C);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0E658E), color-stop(.5, #0C577A), color-stop(.5, #014D71), to(#003E5C)); 
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
    border: 1px solid #368DBE;
    border-top: 1px solid #c3d6df;
    text-shadow: 1px 1px 1px black;      
}

li#menu-item-631 a:hover { 
        background: #003464;
        background: -moz-linear-gradient(top, #0c5f85, #0b5273 50%, #024869 51%, #003853);
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0c5f85), color-stop(.5, #0b5273), color-stop(.51, #024869), to(#003853));
    }

li#menu-item-631 a:active {
        -moz-box-shadow: 0 2px 6px black;
        -webkit-box-shadow: 0 2px 6px black;
    }
    /* FONT GLYPH (MOSTLY FOR FUN) */
li#menu-item-631 a:before {
        font-family: EfonRegular;

        color: #09232F;
        font-size: 90px;
        float: left;
        margin-left: 35px;
        margin-right: -10px;
        text-shadow: 0 1px 0 #4190AF;
    }

This is script in jquery

  <script>
$(window).bind('scroll', function () {
    if ($(window).scrollTop() > 100) {
     $('#navmenu').addClass("menugore");
      $('#navmenu').removeClass("menudole"); 
    } else {
     $('#navmenu').removeClass("menugore");
      $('#navmenu').addClass("menudole"); 
  }
});   
  </script>

I need something like

li#menu-item-631 a.myClass .. Is that possible?

Upvotes: 1

Views: 547

Answers (1)

andyb
andyb

Reputation: 43823

Since you are applying the menugore or menudole class to the parent <ul> element, the selector to target the anchor elements based on that class needs to apply that class on the left side, before the list-item and anchor:

ul.menugore li#menu-item-631 a {}
ul.menudole li#menu-item-631 a {}

This could be simplified to .menugore #menu-item-631 a or just .menugore a if there are no other anchors in the menu. All of the suggestions are examples of the CSS descendent combinator.

Upvotes: 2

Related Questions