Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change one element while hovering over another

Tags:

html

css

I have looked at several other questions but I can't seem to figure any of them out, so here is my problem: I would like to have a div or a span, when you hover over it an area would appear and would be like a drop down.

Such as I have an div, and I want to hover over it and have it show some info about the item I hovered over

<html> <head> <title>Question1</title> <styles type="css/text">    #cheetah {       background-color: red;       color: yellow;       text-align: center;   }    a {       color: blue;   }    #hidden {       background-color: black;    }     a:hover > #hidden {       background-color: orange;       color: orange;   } </styles>  </head> <body>   <div id="cheetah">      <p><a href="#">Cheetah</a></p>   </div>   <div id="hidden">      <p>A cheetah is a land mammal that can run up 2 60mph!!!</p>   </div> </body> </html>

But this ^ doesn't seem to work, I don't know why... and if there is a way to do that in CSS, I would like to know, but I want any and all suggestions.

like image 292
Neros Avatar asked Dec 23 '11 09:12

Neros


People also ask

How do you hover with one element and affect another?

If you have two elements in your HTML and you want to :hover over one and target a style change in the other the two elements must be directly related--parents, children or siblings. This means that the two elements either must be one inside the other or must both be contained within the same larger element.

How do you do different hover effects in CSS?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


1 Answers

You can achieve this in CSS only if the hidden div is a child of the element you use for hovering:

http://jsfiddle.net/LgKkU/

like image 129
ptriek Avatar answered Sep 19 '22 15:09

ptriek