CSS Transition on another class img:hover

CSS Transition on another class img:hover



I have a class with this :hover effect that gives the image color.
And I have this separate class that shows the '+' on :hover, but only when I hover this class. I want to have both :hover effects on one img:hover:



Code for the img:hover effect. (using b/w filter).


.og-grid li > a,
.og-grid li > a img
border: none;
outline: none;
display: block;
position: relative;
-webkit-filter: grayscale(100%);
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0'/></filter></svg>#grayscale");


.og-grid li > a,
.og-grid li > a img:hover
-webkit-filter: grayscale(0%);
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0'/></filter></svg>#grayscale");



Code for the + hover effect.


.viewmore
margin-left: 350px;
opacity: 0;
position: absolute;
z-index: 100;


.viewmore:hover
opacity: 100;
margin-top: 45px;
transition: all ease 0.9s;



HTML (want to apply this on all img in the grid) :
viewmore.png is the '+' img that fades in when I hover it.


<img src="img/viewmore.png" class="viewmore">
<ul id="og-grid" class="og-grid">

<li>
<a href="" data-largesrc="img/work/sunmoon.jpg" data-title="MoonSun Shades" data-description="Swiss chard pumpkin bunya nuts maize plantain aubergine napa cabbage soko coriander sweet pepper water spinach winter purslane shallot tigernut lentil beetroot.">
<img src="img/work/sunmoon2.jpg" alt="img01"/>
</a>
</li>
</ul>



GIF:
https://gyazo.com/fe388835229cf2492a0188f2d29a12df



I want to use see them both at the same time when I hover the img.





Can you post your relavent HTML?
– Michael
Sep 17 '15 at 11:27





Oh yeah forgot ty, Added!
– genghisdong
Sep 17 '15 at 11:46





Why not just put both hover-related pieces of code into your .viewmore:hover - css?
– Philipp Meissner
Sep 17 '15 at 13:03





I dont know how that would look like in css, with a ',' between the different classes? With + or ~ maybe? And I dont want the transition on b/w filter.
– genghisdong
Sep 17 '15 at 13:16





1 Answer
1



The trick is to have the :hover pseudoclass on a parent element. When you hover the parent, you can then move one of the children.


:hover



I've reorganised your code a bit and introduced more semantic class names:




.view-more img.main
transition: all 1s ease;
display: block;
-webkit-filter: grayscale(100%);
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0'/></filter></svg>#grayscale");


.view-more:hover img.main
-webkit-filter: grayscale(0%);
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0'/></filter></svg>#grayscale");

.view-more
position: relative; /* needed for child absolute positioning */
display: inline-block;
overflow: hidden;

.view-more .button
right: 10px;
top: -80px;
position: absolute;
z-index: 100;
opacity: 0;
transition: all 1s ease;
border: 1px red solid;

.view-more:hover .button
top: 0;
opacity: 1;


<a href="#" class="view-more">
<img class="main" src="https://via.placeholder.com/350x150" alt="img01" width="200"/>
<img src="https://via.placeholder.com/50x50" class="button" width="50">
</a>





Thanks! Now it works for all my grid images exactly how I wanted it. But now I have some other weird glitches so trying to fix those now :p If I can't ill leave another reply.
– genghisdong
Sep 17 '15 at 15:53





Fixed it all! Thx Michael, keep up the good work.
– genghisdong
Sep 17 '15 at 16:22





Glad to hear. You're welcome.
– Michael
Sep 18 '15 at 10:53






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)