Here you go, you should use adjacent selector of css.
#menu img:hover + ul { background:red; }
What does the "+" (plus sign) CSS selector mean?
For you to appreciate the goodness, here's a jsfiddle for you.
https://jsfiddle.net/g4frLaak/2/
Ohh, and fix your html code. Remove the end tag of image you've just created. It does not exists.
<div id="menu">
<img id="mb"
src="MenuButton.png"
draggable="false"
style="-moz-user-select: none;"
ondragstart="return false;"
onmouseover="this.src='MenuButtonHover.png'"
onmouseout="this.src='MenuButton.png'">
<ul>
<li><a href="#">Omg look at this!</a></li>
</ul>
</div>
EDIT
To answer your concern in my comment section.
Does it stay open when I also hover over the text inside or just over
the pic? It dosen't stay open for me
I've revised the html code. What I did is, just add another wrapper for both image and the ul
element. So when you hover the link-wrapper
, the ul inside it will take effect on the css. Assuming that there will be more img and menu inside #menu
, we would want to make it dynamic.
#menu .link-wrapper:hover ul { background:red; }
<div id="menu">
<div class="link-wrapper">
<img id="mb"
src="https://www.gravatar.com/avatar/7776e0b99bcafda15ca8c66946e6a623?s=32&d=identicon&r=PG&f=1"
draggable="false"
style="-moz-user-select: none;"
ondragstart="return false;"
onmouseover="this.src='https://www.gravatar.com/avatar/7776e0b99bcafda15ca8c66946e6a623?s=32&d=identicon&r=PG&f=1'"
onmouseout="this.src='https://www.gravatar.com/avatar/7776e0b99bcafda15ca8c66946e6a623?s=32&d=identicon&r=PG&f=1'">
<ul>
<li><a href="#">Omg look at this!</a></li>
</ul>
</div>
</div>
Here's the jsfiddle again.
https://jsfiddle.net/g4frLaak/3/
But the downside is, you have to edit your img src javascript when you hover the link-wrapper. Unfortunately I'm not that good in vanilla javascript.
onmouseover="this.src='MenuButtonHover.png'"
onmouseout="this.src='MenuButton.png'"