Quantcast
Viewing all articles
Browse latest Browse all 215

Display Caption on image hover using CSS and HTML

Image may be NSFW.
Clik here to view.
foggy-morning-beautiful-nature-hover-effect-photos-css-html
Caption Display Image hover effect
Image hover effects have become an element in website as its improves the dynamic feel of the site and increases attraction as well. This post will explain a similar effect in which description of the image will be displayed when the visitors hovers over the image. These type of effects will be very useful where the webmaster wants to display info of products in limited space.


CSS CODE:

  1. .wrap {
  2.           border:10px solid #fff;
  3. display: inline-block;
  4. text-align: left;
  5. position: relative;
  6.          -webkit-box-shadow: 5px 5px 5px #111;
  7.           box-shadow: 5px 5px 5px #111;  
  8.           }
  9. .display {
  10.         position: relative;
  11. overflow: hidden;
  12.               }
  13. .display img {
  14. display: block;
  15.                   }
  16. .caption {
  17. position: absolute;
  18.         width: 100%;
  19. height: 100%;
  20. padding: 10px;
  21. box-sizing: border-box;
  22. -moz-box-sizing: border-box;
  23. -webkit-box-sizing: border-box;
  24. background: rgba(0,0,0,0.4);
  25. color: #fff;
  26. top: 100%;
  27. -webkit-transition: all 0.5s ease-in 0s;
  28. -moz-transition: all 0.5s ease-in 0s;
  29. -o-transition: all 0.5s ease-in 0s;
  30. transition: all 0.5s ease-in 0s;
  31.             }
  32. .wrap:hover .caption {
  33.                           top: 0;
  34.                               }
  35. #txt_stl{
  36.           text-align:center;
  37.           font-size:20px;
  38.           margin-top:50%;
  39.                }

The CSS code of the above effect consists of four elements. The ".wrap" is used to assign a container to the image we are about to use. The second element ".display" is used to position the image and hide overflowing of caption elements. The class ".caption" used to define the look and appearance of caption. And last "#txt_stl" to alter the appearance and position of our caption text. 


HTML CODE:

  1. <div class="wrap">
  2.      <div class="display">
  3. <img src="Your image URL" width="250" height="250" />
  4.         <div class="caption">
  5.             <div id="txt_stl">
  6.                   Foggy Morning
  7.             </div>
  8.         </div>
  9.     </div>
  10. </div>

The HTML part of this effect is simple, all you have to do is place the txt inside the <div> container with proper class and id's used in your CSS code.

Like this article? Share this with others through social sites and don't forget to follow us there for more of these contents. Post your comments and queries regarding this article below. Thank you for visiting and comeback again.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 215

Trending Articles