Image hover effect with caption
A Pen by Pali Madra on CodePen.
Image hover effect with caption
A Pen by Pali Madra on CodePen.
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Image Hover Effect</title> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <figure class="image-container"> | |
| <img src="http://dribbble.s3.amazonaws.com/users/252377/screenshots/1116378/m412c0-app-calendar_2x_1x.png" alt="All Calendar Icon" width="400" height="300"> | |
| <figcaption class="clearfix"> | |
| <h4>App Calendar Icon</h4> | |
| <p>by <a href="http://dribbble.com/m412c0" target="_blank">m412c0</a></p> | |
| <a href="https://twitter.com/m412c0b" class="button" target="_blank">Twitter</a> | |
| </figcaption> | |
| </figure> | |
| </div> | |
| </body> | |
| </html> |
| @charset "utf-8"; | |
| /* CSS Document */ | |
| /* ---------- GENERAL ---------- */ | |
| body { | |
| background: #f2f2f2; | |
| font: 87.5%/1.5em sans-serif; | |
| margin: 0; | |
| } | |
| a { | |
| color: #ea4c89; | |
| text-decoration: none; | |
| } | |
| a:hover { | |
| color: #df3e7b; | |
| } | |
| h4 { | |
| color: #fff; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| img { | |
| bottom: 0; | |
| display: block; | |
| height: auto; | |
| max-width: 100%; | |
| } | |
| figure { | |
| margin: 0; | |
| } | |
| p { | |
| margin: 0; | |
| } | |
| /* ---------- CLASSES ---------- */ | |
| .container { | |
| height: 312px; | |
| left: 50%; | |
| margin: -156px 0 0 -206px; | |
| position: absolute; | |
| top: 50%; | |
| width: 412px; | |
| } | |
| .button { | |
| background: #0084b4; | |
| border-radius: 3px; | |
| color: #fff; | |
| display: inline-block; | |
| font-weight: bold; | |
| padding: 4px 8px; | |
| position: absolute; | |
| right: 20px; | |
| top: 30px; | |
| } | |
| .button:hover { | |
| background: #2D76B9; | |
| color: #fff; | |
| } | |
| /* ---------- IMAGE-CONTAINER ---------- */ | |
| .image-container { | |
| border: 6px solid #fff; | |
| box-shadow: 0 0 5px rgba(0, 0, 0, .3); | |
| overflow: hidden; | |
| position: relative; | |
| width: 400px; | |
| } | |
| .image-container img { | |
| -webkit-transition: all .4s; | |
| -moz-transition: all .4s; | |
| -ms-transition: all .4s; | |
| -o-transition: all .4s; | |
| transition: all .4s; | |
| } | |
| .image-container:hover img { | |
| -webkit-transform: translateY(-45px); | |
| -moz-transform: translateY(-45px); | |
| -ms-transform: translateY(-45px); | |
| -o-transform: translateY(-45px); | |
| transform: translateY(-45px); | |
| } | |
| .image-container:hover figcaption { | |
| opacity: 1; | |
| -webkit-transform: translateY(0); | |
| -moz-transform: translateY(0); | |
| -ms-transform: translateY(0); | |
| -o-transform: translateY(0); | |
| transform: translateY(0); | |
| -webkit-transition: -webkit-transform .4s, opacity .1s; | |
| -moz-transition: -moz-transform .4s, opacity .1s; | |
| -ms-transition: -ms-transform .4s, opacity .1s; | |
| -o-transition: -o-transform .4s, opacity .1s; | |
| transition: transform .4s, opacity .1s; | |
| } | |
| .image-container figcaption { | |
| background: #283449; | |
| bottom: 0; | |
| color: #fff; | |
| height: 50px; | |
| left: 0; | |
| opacity: 0; | |
| padding: 20px; | |
| position: absolute; | |
| -webkit-transform: translateY(100%); | |
| -moz-transform: translateY(100%); | |
| -ms-transform: translateY(100%); | |
| -o-transform: translateY(100%); | |
| transform: translateY(100%); | |
| -webkit-transition: -webkit-transform .4s, opacity .1s .3s; | |
| -moz-transition: -moz-transform .4s, opacity .1s .3s; | |
| -ms-transition: -ms-transform .4s, opacity .1s .3s; | |
| -o-transition: -o-transform .4s, opacity .1s .3s; | |
| transition: transform .4s, opacity .1s .3s; | |
| width: 360px; | |
| } |