1

I have a list of pictures and when I hover on a picture, I want the rest of pictures turn to black and the one which I'm hovering stays in its original color. would you please help me to do it?

.inst__img { width: 11%; margin-left: 10%; display: inline-block; } .inst__img img { width: 100% }
<section class="global__inst"> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> </section>

3 Answers 3

6

You need to select not hovered images for grayscale: img:not(:hover)

.inst__img { width: 11%; margin-left: 10%; display: inline-block; } .inst__img img{ width: 100%; } .global__inst:hover img:not(:hover) { filter: grayscale(1); -webkit-filter: grayscale(1); }
<section class="global__inst"> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> </section>

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

1 Comment

Greant answer!!
1

Use this:

.inst__img { width: 11%; margin-left: 10%; display: inline-block; } .inst__img img { width: 100% } .global__inst:hover .inst__img img { filter: grayscale(100%); } .inst__img:hover img { filter: none !important; }
<section class="global__inst"> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> <div class="inst__img"> <img src="https://media.wired.com/photos/598e35994ab8482c0d6946e0/master/w_2560%2Cc_limit/phonepicutres-TA.jpg" alt=""> <span>vi</span> </div> </section>

2 Comments

Why don't you post an executable snippet?
Thanks for the snippet, small typo, fixed my code. But mplungjan answer should be accepted, it's better.
0

please try the below one. initial all the list images will be black and the hover one can display as you like

.inst__img{ border:2px solid red; background: black; opacity:.5 } .inst__img:hover{ border:2px solid red; background: white; opacity:1 } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.