0

I would like to show an img when i hover over another but nothing is happening. Any advice on what i can do to change the code

**HTML**
 <div id="container-collection">

   <img class="clothes1" src="Images/smallest/JPEG/IMG_3148.jpg">

   <img class="closeup1" src="Images/Smaller/bigger ones/JPEG/IMG_3148_1.jpg">

 </div>

**CSS**

img.closeup1{
    display: none;
}

img.closeup1:hover clothes1 {
    display: block;
}

2 Answers 2

1

As @minitech said, you need to properly combine the controlled element selector with the :hover owner.

I'd go for something like this:

HTML

<div id="container-collection">
    <div class="clothes1-wrap">
        <img class="clothes1" src="Images/smallest/JPEG/IMG_3148.jpg">
        <img class="closeup1" src="Images/Smaller/bigger ones/JPEG/IMG_3148_1.jpg">
    </div>
</div>

CSS

.closeup1 {
    display: none;
}

.clothes1-wrap:hover .closeup1 {
    display: block;
}

For me, this looks a little bit cleaner, plus you can add elements between imgs.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks very much, that sorted it. Been messing about with it for hours.
1
  1. You're missing a . to select a class. It should be .clothes1.
  2. You're missing a combinator; .clothes1 is not a descendant of .closeup1. However, unfortunately, there doesn't yet exist a combinator for "previous sibling". In CSS4, there will be, but not now.

If shuffling the order is okay (you may be able to correct the positioning change with some fancy CSS), you can do this:

<div id="container-collection">

    <img class="closeup1" src="Images/Smaller/bigger ones/JPEG/IMG_3148_1.jpg">

    <img class="clothes1" src="Images/smallest/JPEG/IMG_3148.jpg">

</div>
img.clothes1 {
    display: none;
}

img.closeup1:hover + .clothes1 {
    display: block;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.