0

I am trying to make a menu where I show the icon and when i hover over the icon the text will appear. I've got that so far, but I want to change the background color of the text.

<div id='menu'>
    <div id='menuitems'>
        <div class="item" onclick="loadPage('/')">
            <span class="menuIcon"><img src='/img/layout/icons/home.png'/></span>
        </div>
        <div class="item" onclick="loadPage('/pages/settings/')">
            <span class="menuIcon"><img src='/img/layout/icons/settings.png' /></span>
        </div>
        <div class="item" onclick="loadPage('/pages/php/')">
            <span class='TextMenuItem'>< &#47; ></span>
        </div>
    </div>
    <div id="menuText">
        <div class="itemtext" onclick="loadPage('/pages/home/')">Home</div>
        <div class="itemtext" onclick="loadPage('/pages/settings/')">Settings</div>
        <div class="itemtext" onclick="loadPage('/pages/php/')">Projects</div>
    </div>
</div>

So if I move over a div with the class item I want to change the color of the div and the div with the class itemtext. Is it possible, in css, to see how many times a class has been used before the one that I hover and based on that number being able to color the background of the itemtext div with the same number or do I have to use javascript?

JSFiddle with progress: http://jsfiddle.net/WszKV/

Gert Kommer
  • 1,163
  • 2
  • 22
  • 49

2 Answers2

0

I think

.item:hover .itemtext:hover{
  color: <new color>;
  background-color: <new color>;//if that is what you were looking for
}

should work.

Aneesh
  • 279
  • 3
  • 11
0

Ended up using javascript to solve my problem.

$('.item').hover(
    function() {
        var index = $(this).index();
        changeMenuBg(index, true);
    }, function() {
        var index = $(this).index();
        changeMenuBg(index, false);
    }
)
$('.itemtext').hover(
    function() {
        var index = $(this).index();
        changeMenuBg(index, true);
    }, function() {
        var index = $(this).index();
        changeMenuBg(index, false);
    }
)
function changeMenuBg(index, hover){
    if(hover){
        $($('.item').get(index)).css('background-color','#FF2400');
        $($('.itemtext').get(index)).css('background-color','#FF2400');
    }
    else{
        $($('.item').get(index)).css('background-color','');
        $($('.itemtext').get(index)).css('background-color','');
    }
}
Gert Kommer
  • 1,163
  • 2
  • 22
  • 49