Grow your CSS skills. Land your dream job.

Nice Image Hover Effect

  • # November 23, 2012 at 5:08 am

    I seen a similar effect that used jQuery and thought I would see if I could make it in CSS only.

    [So here it is](http://codepen.io/alexmccabe/pen/sfFBi “cool hover”)

    The HTML could probably be improved upon, and the CSS might be able to be condensed, but it only took me a few minutes. Hope you like it =]

    # November 23, 2012 at 8:25 am

    Thanks for sharing.

    Just wondered if it would be possible to reverse this effect so that the figcaption is shown first and then on hover it’s not?

    Thanks.

    # November 23, 2012 at 8:54 am

    Yep, that’s easy enough.

    I was wondering if it could be done without the unsemantic span though.

    I would have thought that a lot of the styling on that could be applied to the fig caption.

    # November 23, 2012 at 10:08 am

    @Paulie_D How would this be done?

    Sorry I’ve had a look and I’m completely lost.

    Thanks.

    # November 23, 2012 at 10:11 am

    @paulie_d, yeah I tried it but the figcaptions are an odd one to work with. I am gonna keep working on it, and see what I can come up with. But it only took me a few minutes doing it this way.

    DeTodo [Here is the reverse effect](http://codepen.io/alexmccabe/pen/sELFA “reversed”). Basically it works on the opacity of fig caption and the span.

    # November 23, 2012 at 10:17 am

    thank you @alexmccabe

    Going to try make this work on my site

    # November 23, 2012 at 10:18 am

    > Going to try make this work on my site

    I’d love to see it when it’s done, and if you get stuck send me a tweet [@alexwmccabe](https://twitter.com/alexwmccabe “twitter”)

    # November 23, 2012 at 10:31 am

    Cheers.

    I’m going to try implement it here

    http://www.detodo.co.uk

    Still trying to work out the process in my head, but I’ll most probably be taking you up on your offer for help. Very kind of you.

    Thanks.

    # November 23, 2012 at 10:34 am

    Here’s where I am without the span or the extra link.

    http://codepen.io/Paulie-D/pen/teKiB

    I’m sure there is a lot that can still be done.

    # November 23, 2012 at 10:41 am

    I [updated](http://codepen.io/alexmccabe/pen/sELFA “updated”) the reverse that you asked for with CSS comments, so that you can hopefully understand what is happening. It really is very simple, it just looks like a lot.

    # November 23, 2012 at 10:45 am

    Paulie_D, hmm odd the figcaptions seem to be playing nice for you, but when I tried with it, they seemed to sit way off from the left and top and had to use minus numbers to get them to line up…Thanks =]

    DeTodo, I would take Paulie_D’s code for use, but, notice the image isn’t centered.

    # November 23, 2012 at 11:08 am

    Here is the general idea but please bear in mind that improvement can always be made.

    See, you’ve wrapped in a div which isn’t really necessary as a figure is just a div with a ‘specific’ function and so acts the same.

    So, once I’ve defined the width & height I just set a positioning context (relative).

    Then, since the figcaption is inside the figure, I can apply absolute positioning (top:0) and it’s automatically aligned. Granted you have to make it the same size as the image but having set specific dimensions on the figure and overflow:hidden it won’t matter.

    Then set the opacity to ‘0’ as you did and transition that on hover.

    You can make sure that the cursor can see through the figcaption to the underlying link by using the ‘pointer-events’ property and so you don’t need to link the figcaption text at all.

    Whew.

    Is it perfect? Nope, and we’re not exactly using the figure element in the way it’s supposed to be used but you could replace the figure & figcaption with divs and it would still work..you’d just need a couple of extra classes.

    # November 23, 2012 at 11:10 am

    Once more thing…I’m wondering if it wouldn’t be possible to avoid setting image sizes specifically if we could use the transition/transform:scale property.

    Hmmm.

    # November 23, 2012 at 3:58 pm

    Paulie_D, you are a star. I don’t actually have a use for this, I did it because I could, but you have bettered me. I knew it could be, but thank you =]

    # November 23, 2012 at 7:27 pm

    Thank you both. :)

    Just went through the link and it’s very well explained. Thank you so much.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".