Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Add Twitch-like hover effect to a picture
Christophe
Christophe

Posted on

     

Add Twitch-like hover effect to a picture

I based this code on the CodePen link byArnaud Delante, but I thought it might be handy to make an article of this.

It's pretty straight forward and you can change stuff to your liking.

1. HTML

Import a stylesheet, show some pictures and write out the HTML code.

For every picture that needs the hover effect, we have to wrap it in a separate container div, like this:

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><linkrel="stylesheet"type="text/css"href="style.css"><title>Document</title></head><body><divclass="container"><imgclass="picture"src="picture.jpeg"alt="picture"></div><divclass="container"><imgclass="picture"src="picture2.jpeg"alt="picture"></div></body></html>
Enter fullscreen modeExit fullscreen mode

2. CSS

Use your class names and use this CSS code:

body{text-align:center;}.container{display:inline-block;margin:50px;background-color:red;}.container:before,.container:after{display:block;background-color:red;width:8px;height:8px;position:absolute;transition:all.15sease;}.container:before{top:0;left:0;transform-origin:topleft;transform:rotate(-45deg)scale(0);}.container:after{right:0;bottom:0;transform-origin:bottomright;transform:rotate(45deg)scale(0);}.picture{height:300px;display:block;transform:translate(0,0);transition:all.15sease;z-index:10;}.container:hover.picture{transform:translate(6px,-6px);}.container:hover:before{transform:rotate(-45deg)scale(1);}.container:hover:after{transform:rotate(45deg)scale(1);}
Enter fullscreen modeExit fullscreen mode

I just used a simple red background color. Of course, you can add any color you like. Or tweak any other of these variables.

Live demo

hover

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
afif profile image
Temani Afif
Your favorite CSS Hacker
  • Joined

Sounds a bit overkill, you can do it with box-shadow and only 3 lines of CSS:jsfiddle.net/7oy810nw/1/

CollapseExpand
 
chadriae profile image
Christophe
Started coding not so long ago. Now a full stack developer with strong interest in everything web dev.Coffee, music and 26-inch bike enthousiast.
  • Location
    Ghent, Belgium
  • Joined

Thanks for this. So this article has 2 solutions then.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Started coding not so long ago. Now a full stack developer with strong interest in everything web dev.Coffee, music and 26-inch bike enthousiast.
  • Location
    Ghent, Belgium
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp