HTML/CSS Tutorials

Web Design Blog / HTML/CSS Tutorials / CSS3 Hover Effects

CSS3 Hover Effects

Tags:

Hello guys, this time I will show you other five examples of hover effects using different CSS properties compared to the old tutorial posted on Codrops. In summary, we seek the same method but we will act especially using the border property, as we shall see later that allows us to create very particular effects. Please note that this will only work properly in modern browsers that support the CSS3 properties in use.

CSS3 Hover Effects - DEMO

HTML Markup

This simple structure allows us to make these effects. As you can see in the code below we create a parent class view, and the contents inside. Then we create a class mask where we apply CSS3 transitions to get the hover effect. In later examples, this syntax could change slightly depending on the effect you want to apply.

<div class="view">  
      <img src="images/1.jpg" />  
      <div class="mask"></div>  
      <div class="content">  
           <a href="#" class="info" title="Full Image">Full Image</a>  
      </div>  
</div>   

CSS

Here you will set the basic properties of our tutorial. For every effect there will be a different CSS file, you can incorporate the various effect into one CSS file.

.view {
   width: 300px;
   height: 200px;
   margin: 10px;
   float: left;
   border: 5px solid #fff;
   overflow: hidden;
   position: relative;
   text-align: center;
   box-shadow: 0px 0px 5px #aaa;
   cursor: default;
}
.view .mask, .view .content {
   width: 300px;
   height: 200px;
   position: absolute;
   overflow: hidden;
   top: 0;
   left: 0;
}
.view img {
   display: block;
   position: relative;
}
.view a.info {
   background:url(../img/link.png) center no-repeat;
   display: inline-block;
   text-decoration: none;
   padding:0;
   text-indent:-9999px;
   width:20px;
   height:20px;
}

1 Example

CSS3 Hover Effects - 1 Example

HTML

Add the special class effect to the element with the class view for this effect.

<div class="view effect">  
      <img src="images/1.jpg" />  
      <div class="mask"></div>  
      <div class="content">  
           <a href="#" class="info" title="Full Image">Full Image</a>  
      </div>  
</div>   

CSS

As we see it is very easy to create animations of really interesting, for reasons of space I have omitted the prefixes (-moz-,-webkit- etc.) but you will find all prefixes in the file.
In addition to using the border property to create a triangle, I used the multiple transitions that allows me to have more control on each property during the animation.

.effect img {
   opacity:1;
   transform:scale(1,1);
   transition: all 0.2s ease-in;
}
.effect .mask {
   opacity:0;
   overflow:visible;
   border-color:rgba(0,0,0,0.7) transparent transparent transparent;
   border-style:solid;
   border-width:150px;
   width:0;
   height:0;
   transform:translateY(-125px);
   transition: transform 0.2s 0.1s ease-out, opacity 0.3s ease-in-out;
}
.effect a.info {
   opacity:0;
   transform:translateY(-125px);
   transition: transform 0.3s ease-in, opacity 0.1s ease-in-out;
}
.effect:hover img {
   opacity:0.7;
   transform:scale(2,2);
}
.effect:hover .mask {
   opacity: 1;
   transform: translateY(0px);
}
.effect:hover a.info {
   opacity:1;
   transform:translateY(100px);
}

2 Example

CSS3 Hover Effects - 2 Example

HTML

The syntax in this example is slightly different, always enough add special class second-effect to the class view, but we're going to include the link inside the class mask.

<div class="view second-effect">  
     <img src="images/2.jpg" />  
     <div class="mask">  
         <a href="#" class="info" title="Full Image">Full Image</a>  
     </div>  
</div>  

CSS

In this example we are going to operate on the parameters of the border property. I also implemented the box-sizing. The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements.

.second-effect .mask {
   opacity: 0;
   overflow:visible;
   border:0px solid rgba(0,0,0,0.7);
   box-sizing:border-box;
   transition: all 0.4s ease-in-out;
}
.second-effect a.info {
   position:relative;
   top:-10px;
   opacity:0;
   transform:scale(0,0);
   transition: transform 0.2s 0.1s ease-in, opacity 0.1s ease-in-out;
}
.second-effect:hover .mask {
   opacity: 1;
   border:100px solid rgba(0,0,0,0.7);
}
.second-effect:hover a.info {
   opacity:1;
   transform:scale(1,1);
   transition-delay:0.3s;
}

3 Example

CSS3 Hover Effects - 3 Example

HTML

Add to the class view the special class third-effect for this effect.

<div class="view third-effect">  
     <img src="images/3.jpg" />  
     <div class="mask">  
         <a href="#" class="info" title="Full Image">Full Image</a>  
     </div>  
</div>  

CSS

As we see with very few lines of code we can get a nice effect thanks to the border property.

.third-effect .mask {
   opacity: 0;
   overflow:visible;
   border:100px solid rgba(0,0,0,0.7);
   box-sizing:border-box;
   transition: all 0.4s ease-in-out;
}
.third-effect a.info {
   position:relative;
   top:-10px; /* Center the link */
   opacity: 0;
   transition: opacity 0.5s 0s ease-in-out;
}
.third-effect:hover .mask {
   opacity: 1;
   border:100px solid rgba(0,0,0,0.7);
}
.third-effect:hover a.info {
   opacity:1;
   transition-delay: 0.3s;
}

4 Example

CSS3 Hover Effects - 4 Example

HTML

The markup in this example is reduced compared to the previous examples, but the hover effect will be very impressive.

<div class="view fourth-effect">  
    <a href="#" title="Full Image"><img src="images/4.jpg" /></a>  
    <div class="mask"></div>  
</div>  

CSS

Using only the class mask in combination with the border-radius property will really take a beautiful hover effect. I also used the visibility which allows the transition end to have the image clickable.

.fourth-effect .mask {
   position:absolute; /* Center the mask */
   top:50px;
   left:100px;
   cursor:pointer;
   border-radius: 50px;
   border-width: 50px;
   display: inline-block;
   height: 100px;
   width: 100px;
   border: 50px solid rgba(0, 0, 0, 0.7);
   box-sizing:border-box;
   opacity:1;
   visibility:visible;
   transform:scale(4);
   transition:all 0.3s ease-in-out;
}
.fourth-effect:hover .mask {
   opacity: 0;
   border:0px solid rgba(0,0,0,0.7);
   visibility:hidden;
}

5 Example

CSS3 Hover Effects - 5 Example

HTML

This last example has the same syntax matches the 4 example, the only difference being that one must add the class fifth-effect instead of fourth-effect.

<div class="view fifth-effect">  
    <a href="#" title="Full Image"><img src="images/5.jpg" /></a>  
    <div class="mask"></div>  
</div> 

CSS

Also here we will use the border property with the visibility property. As you can see the trick is to change the border property to be solid to double.

.fifth-effect img {
   opacity:0.2;
   transition: all 0.3s ease-in;
}
.fifth-effect .mask {
   cursor:pointer;
   opacity:1;
   visibility:visible;
   border:100px solid rgba(0,0,0,0.7);
   box-sizing:border-box;
   transition: all 0.4s cubic-bezier(0.940, 0.850, 0.100, 0.620);
}
.fifth-effect:hover .mask {
   border:0px double rgba(0,0,0,0.7);
   opacity:0;
   visibility:hidden;
}
.fifth-effect:hover img {
   opacity:1;
}

Conclusion

I hope that you liked these experiments, but above all I hope that they can inspire you for your projects. Thanks for your time.

Share and Enjoy:

  • Twitter
  • Facebook
  • LinkedIn
  • del.icio.us
  • StumbleUpon
  • Digg
  • Google Buzz
  • Reddit
  • RSS
  • blogmarks
  • Design Float
  • Diigo
  • DZone
  • email
  • FriendFeed
  • Identi.ca
  • Ping.fm
  • Plurk
  • Posterous
  • Slashdot
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tumblr

About The Author

Alessio Atzeni, based in Rome, Italy, is a dedicated web designer and front-end developer with a passion for CSS3. He specializes in CSS and JavaScript web development, and building search engine friendly websites. For more front-end web development tutorials and CSS3 experiments, check out his web design blog. Follow him on Twitter @Bluxart or add him on Google+

14 comments…Add Comment

  1. Andrea Rufo

    Davvero belli e interessanti. Ma quale e` la tua opinione in merito all’uso effettivo da farne oggi. Nel senso: dove non sono supportati, cosa succede ed eventualmente cosa conviene fare?

  2. Bluxart

    Grazie, semplice nei browser che non supportano le proprietà CSS3, si può tranquillamente utilizzare Modernizr e inserire uno script apposito solo nell’eventualità che il browser non supporti ad esempio le CSS3 Transitions.

    Le CSS3 Transitions vengono supportate da Chrome, Safari 3.1+, Firefox 4+, Opera 10.5+ e IE10+.

    Ovviamente per gli altri hai due soluzioni, usare Modernizr e CSS3, oppure non usare le CSS3 Transitions e lavorare solo in jQuery.

    Io personalmente trovo più utile utilizzare la soluzione Modernizr + CSS3.

  3. Amrinder Singh

    Very good examples of hover effects.

  4. Joel Hummel

    Thank you for contributing this tutorial! I downloaded the example and want to learn it better by experimenting with it myself. Credit to you!

  5. Sumit Nagpal

    Nice Collection. I really Like It.

    Thanks for Share. Keep it up. :)

  6. Joshua

    HOT GIRL O_O

  7. VenomVendor

    Coool Effects, i like the Demo-$ very much :)

  8. falguni patel

    Nice effects but can not work in Internet explorer ……. :(

  9. Nora Reed

    Thanks for sharing this tutorial. Great effects!

  10. Ope

    awesome demo’s. thanks for sharing.

  11. Martin

    Pretty impressive work! Ill be glad to use it in my next work! Thanks for share it!

  12. Dheeraj

    Great, looks really awesome. And i am very happy to see that all effects are done by css, no jquery. Thanks for sharing

  13. paman doblang bersabda

    wooow really awesome
    this tut inspiring so much
    TY VM

  14. dinesh

    Very Nice thank you for share

Leave a response

Sponsored By