-2

I was creating a simple effect for a webpage. I wanted to show an image when mouse is hovered on a link. The problem is, when I use <br> tag, image is not shown on hover, but when I remove <br> it works.

Can anyone tell me what is the issue here? Why does the <br> obstruct the hover? Here's a snippet showing that <br> is not working:

.imageClass{ 
  display: none; 
} 

a:hover + .imageClass{ 
  display: block; 
}
<a href="http://esmartify.com/">Esmartify</a>
<br>
<!--When i remove this line, image is shown on hover, otherwise not-->
<div class="imageClass">
  <img src="images6/concert.jpg" width="100%">
</div>

Here's a snippet showing it is working without <br>:

.imageClass {
  display: none;
}
a:hover + .imageClass {
  display: block;
}
 <a href="http://esmartify.com/">Esmartify</a>
<!--When i remove this line, image is shown on hover, otherwise not-->
<div class="imageClass">
  <img src="images6/concert.jpg" width="100%">
</div>
Andrew Li
  • 55,805
  • 14
  • 125
  • 143
Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52

2 Answers2

1

My guess is that br behaves as an element between the link and the div. If so, a:hover ~ .imageClass should work.

Esteban Gerpe
  • 344
  • 1
  • 6
0

a:hover + .imageClass - imageClass must be immediately after link, remove br and add to css display:block for link

or try to use: a:hover ~ .imageClass

Alex Muravyov
  • 502
  • 6
  • 13