0
<div class="product">
 <div class="image">
   <div class="mainimage"></div>
   <div class="secondimage"></div>
 </div>
 <div class="productdescription"></div>
</div>

At the mouse hover on class productdescription I want to apply display: block on class secondimage. How can I do it?

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Andrew
  • 61
  • 6
  • 2
    You can't do it without javascript, because the trigger element .productdescription have to be a parent of the element .secondimage. – Y4roc Aug 10 '18 at 14:25

2 Answers2

0

There isn't a way to do this in pure CSS with the structure you have, as a general rule CSS avoids any selectors that 'travel up' the DOM node tree to avoid complexity. However if you swap the order like so:

<div class="product">
 <div class="productdescription"></div>
 <div class="image">
   <div class="mainimage"></div>
   <div class="secondimage"></div>
 </div>
</div>

Then you should be able to do the following using the Adjacent Sibling selector

.productdescription:hover + .image .secondimage{
    display:block;
}

.productdescription:hover + .image .secondimage{
    display:block;
    color:red;
}
<div class="product">
 <div class="productdescription">Product Description</div>
 <div class="image">
   <div class="mainimage">Main Image</div>
   <div class="secondimage">Second Image</div>
 </div>
</div>

Alternatively, if you need to keep the structure, then a bit of JavaScript/jQuery is required.

$(".productdescription").hover(function(){
    $(this).parent().find(".image .secondimage").toggleClass("hoverActive")
});
.secondimage.hoverActive{
    display:block;
    color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="product">
 <div class="image">
   <div class="mainimage">Main Image</div>
   <div class="secondimage">Second Image</div>
 </div>
  <div class="productdescription">Product Description</div>
</div>
ChrisM
  • 1,565
  • 14
  • 24
0

I guess you'll need some JavaScript and jQuery to do this.

After putting an id in each div you want to interact:

$('#productDescription').hover(function(){
    $('#secondImage').css("display","block");
});

I don't know if it's what you looking for, but it works.

Richard Nikolas
  • 505
  • 4
  • 11