-3

head no background and color black ,on mouseover its color will be white and background black ,its working fine but

onmouse over on content i want to change the color of head? how? Is it possible only using css?

 <ul id="meg">
   <li><a href="#">head</a>
    <div>
    <h2>su head</h2>
    <p><a href="#">content</a></p>
    <p><a href="#">content</a></p>
     </div>
    </li>
 <li><a href="#">head</a>
    <div>
    <h2>su head</h2>
    <p><a href="#">content</a></p>
    <p><a href="#">content</a></p>
     </div>
    </li>
</ul>
Prashobh
  • 9,216
  • 15
  • 61
  • 91

3 Answers3

1

this might work. i've knows css to be able to affect elemnts after the closing tag not before,so this is areverse of the "+" used to do that.

<style type="text/css">
   #content:hover - #head { background-color: black; color: white; }
  </style>

 <ul id="meg">
   <div id="head">
   <li><a href="#">head</a>
   </div>
   <div id="content">
    <h2>su head</h2>
    <p><a href="#">content</a></p>
    <p><a href="#">content</a></p>
     </div>
    </li>
    </ul>
Atom Vayalinkal
  • 2,642
  • 7
  • 29
  • 37
1

You can do it with JavaScript. Though I'm not entirely clear on what you wanted, I gave it a shot:

<!DOCTYPE html> 
<html>
<head>
<script type="text/javascript">  
function stuff(){
   var k = document.getElementsByTagName('li');
   for (var i = 0; i < k.length; i++) {
        var s = k[i];     
        s.firstChild.style.color = 'white';
        s.firstChild.style.backgroundColor= 'black';
    }
}
</script>
</head>
<body>
  <ul id="meg">
    <li>
       <a href="#">head</a>
       <div>
          <h2>su head</h2>
          <p><a href="#" onmouseover="stuff()">content</a></p>
       </div>
    </li>
  </ul>
</body>
</html>
RAN
  • 1,443
  • 3
  • 19
  • 30
Smith
  • 70
  • 1
  • 8
0

Have you tried #meg li a:hover { background-color:#000;color:#FFF; }

dilloncarter
  • 35
  • 1
  • 8