0

Html :

<div class="first">
   <div class="first-sub">
       <a href="#"></a> 
   </div>
</div>
<div class="second"></div>

When I hover on a element, need to effect div which has class .second

Can I do this with only css ? or should I use javascript too ?

OwnurD
  • 195
  • 1
  • 3
  • 17

2 Answers2

1

you could use the general sibling selector:

div:hover ~ div.second{background:yellow}
<div class="first">
   <div class="first-sub">
       <a href="#">first</a> 
   </div>
</div>
<div class="second">sec</div>
maioman
  • 18,154
  • 4
  • 36
  • 42
  • Anchor number depends on me, I will use 3 anchor element inside of first-sub div. So this way does not work for my question. – OwnurD Sep 10 '15 at 13:22
0

I found a solution proposed in another forum & in another post here.

.parent-hover-block {
    pointer-events: none;
    background-color: black;
    padding: 15px;
}

.parent-hover-block > span {
    pointer-events: auto;
    background-color: orange;
    margin: 50%;
}

.parent-hover-block:hover ~ .element-to-border-at-span-hover{
    border: 1px dashed red;
}

.element-to-border-at-span-hover{
    margin: 20px;
    padding: 15px;
    text-align: center;
}
<div class="parent-hover-block">
<span>Hovered child (icon)</span> 
</div>
<div class="element-to-border-at-span-hover"> Block to be border at span hover</div>

But be careful with pointer-events.

More info here : How to style the parent element when hovering a child element?

Delphine
  • 861
  • 8
  • 21