Reputation: 855
I've started with css just day ago so I'm new to this.I'd like to achieve moving blue rectangle when I move mouse on red rectangle.I'm sure hover is able to handle this event, but I don't really know how to work with parent/child relationship.Thank you.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<style>
#first
{
width:50px;
height:50px;
position: relative;
top:100px;
left:100px;
background: red;
}
#second
{
width:50px;
height:50px;
position: relative;
top:200px;
left:200px;
background: blue;
transition: left 1s;
}
#first:hover + #second
{
left:250px;
}
</style>
<div id="first">
<div id="second"></div>
</div>
</body>
</html>
Upvotes: 0
Views: 48
Reputation: 17366
Use child >
selector as +
is for siblings:
#first:hover > #second
{
left:250px;
}
Upvotes: 2
Reputation: 4046
Use the child selecter (>) not sibling selector (+)
#first:hover > #second
{
left:250px;
}
Upvotes: 0