Hover shine effect with pure CSS

This is a simple example of a mouse-over shine effect I created using purely CSS. It uses a CSS generated element and CSS3 transitions to animate the effect. See the comments in the markup below for further explanation of how it works.

Live demo:

Click Me

Simple HTML markup:
[cc lang=”html”]

Click Me

[/cc]

And the CSS:
[cc lang=”css”]
/* normal button style */
.myButton {
width: 110px;
height: 30px;
background-color:#0099cc;
text-align: center;
color: #FFF;
position: relative;
}
/* button hover style if required */
.myButton:hover {

}
/* generated element for shine effect.
* normal state is semi-transparent
* white but with zero width. Set no
* transition here for no mouse-leave
* animations. Otherwise the effect
* will play in reverse when your mouse
* leaves the element
*/
.myButton:after {
content: “”;
position: absolute;
top: 0px;
left: 0px;
width: 0%;
height: 100%;
background-color: rgba(255,255,255,0.4);
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: none;
transition: none;

}
/* on hover we animate the width to
* 100% and opacity to 0 so the element
* grows and fades out
*/
.myButton:hover:after {
width: 120%;
background-color: rgba(255,255,255,0);
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
[/cc]


Comments

9 responses to “Hover shine effect with pure CSS”

  1. Łukasz Avatar
    Łukasz

    Hello. Can someone explain me, why these effects work properly only in Firefox and Chrome? (Maybe this code work smoothly also in IE – but, I do not have this browser, and I cannot check this out).

    Now I try to find some reason such a state of thing, and I will be happy if someone helps me solve this problem, or maybe knows some method, to make similarly effect with java script.

    I’m really sorry for my English. =)

    1. i beleive IE9 and below don’t support css RGBA colours

      1. Łukasz Avatar
        Łukasz

        All right Ben – but what with Opera and Safari? I test your code in both (Opera 12.14, Safari 5.1.7) and I do not see any transition effect. Those browsers, in these versions, support RGBA syntax. This several lines of code looks good and I am impressed your idea, but in both of this browsers must by some bugs. I am wondering what and how to fix them.

  2. Can anybody post how to move the image with hover effect?

    http://thishdreamz.com

  3. ling maaki Avatar
    ling maaki

    try this some good CSS Image hover effects…Image Hover

    Ling

  4. darkace Avatar
    darkace

    If you fiddle with the starting position at myButton:after { …. left: 50%; …. } you can center this animation on myButton:hover:after { width: 100%; left: 0; …. } which looks quite nice

  5. i want animation from upper-left corner to bottom-right corner … what should i do ?

    1. you can set height to 0 on the “after” part, and to “100%” on the “:hover:after” part

Leave a Reply