Reputation: 7
There are a couple questions like this, but to make it clear, I need to hover over one element and have another element transition, not simply having it pop back and forth (for example, this).
Essentially, this is what I want: http://jsfiddle.net/jMEL7/2/ Except that it needs to transition when I'm hovering over either of the two buttons and not when I'm hovering over the image.
Iv'e tried using selectors, but that doesn't work. I wish I could just do this:
#lb:hover {
h {
webkit-transform:rotate(270deg);
transform:rotate(270deg)
}
}
From the other posts, it seems JS is the only way. I don't know jQuery, so I'm lost.
Upvotes: 0
Views: 139
Reputation: 11506
You can use adjacent sibling combinator (+
), but only if #h
is after #lb
in the HTML.
#lb:hover + #b {
// your style
}
If there are other elements between #h
and #lb
, you can use (~
) combinator.
#lb:hover ~ #h {
// your style
}
e.g -
#lb:hover ~ #h {
-webkit-transform:rotate(270deg);
transform:rotate(270deg)
}
For child and siblings selector read
Finally
#main > a:nth-child(1):hover ~ a:nth-child(3) img {
-webkit-transform:rotate(270deg);
transform:rotate(270deg)
}
#main > a:nth-child(2):hover ~ a:nth-child(3) img {
-webkit-transform:rotate(270deg);
transform:rotate(270deg)
}
Upvotes: 1
Reputation: 9460
HTML
<input type="button" id="lb" value="Button">
<img src="http://playrust.com/wp-content/uploads/2013/12/rust-icon-512.png"
id="h" height="130px"/>
CSS
#lb {
float:right;
color:#6C2D58;
font-size:40px;
font-family:Impact;
transition: 1s;
}
#lb:hover {
background-color:#D88E79;
}
#h {
transition:1s;
}
#lb:hover ~ #h {
-webkit-transform:rotate(270deg);transform:rotate(270deg);
}
Upvotes: 0
Reputation: 8975
I placed your input tag before img tag so I can use adjacent sibling combinator(+)
<input type="button" id="lb" value="Button">
<img src="http://playrust.com/wp-content/uploads/2013/12/rust-icon-512.png" id="h" height="130px"/>
CSS code:
#lb:hover + #h {
-webkit-transform:rotate(270deg);transform:rotate(270deg);
}
Upvotes: 1