Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set CSS hover effect, on parent and child elements

Tags:

css

hover

Let's say i have the following code:

<div class="wrapper">
  <div class="title"></div>
  <div></div>
</div>

<div class="wrapper">
  <div class="title"></div>
  <div></div>
</div>

<div class="wrapper">
  <div class="title"></div>
  <div></div>
</div>

On hover for a wrapper I want it's child title div to change it's background color. Can I do this in pure css. In js I know how to do it. I'm interested if a pure CSS method exists for this?

Thanks

like image 431
Tamás Pap Avatar asked Jan 19 '12 13:01

Tamás Pap


2 Answers

Yes, you can do this. It's just:

.wrapper:hover .title {
  background-color: #f00;
}

EDIT:
Please note that IE6 recognizes :hover only on a-elements, so this won't work - but i hope you don't have to mess with that crappy old thing.

like image 108
oezi Avatar answered Oct 12 '22 13:10

oezi


what about this?

.wrapper:hover .title {
    background-color: blue;
}
like image 31
Marcelo Diniz Avatar answered Oct 12 '22 13:10

Marcelo Diniz