Sunday, January 19, 2014

// // Leave a Comment

Simple & Cool Live Examples of Image on hover Css effect

We will be playing with Image on hover effects using CSS  and One image only. I’ve created four simple examples that will work in all  browsers and another six cooler ones that will work only on webkit browsers.
They are all hosted on Codepen so you can directly play with the code and learn in the process. I  didn’t  even make any extra div to confuse you – all the images are in their main IMG tag. I’ll try to keep it short and sweet so you can absorb it even if you never touched CSS before.
In all the examples below we use this two simple things :
For CSS
img {here is the code of the initial state of the image}
and
img:hover { here is the code of the hover state of the image}
For HTML
 src="http://link to the image">
This extra div below ↓ is used  to center things on the Screen JUST IGNORE IT
style="text-align:center">
The first four live examples will work in all the modern browsers
box shadow browser support 
Lets get this party started…
Simple & Cool Live Examples of Image on hover Css effect

Shrink Image on hover

In this example we have  :hover  using height and width to change the size of the image, by adding  transition: all 1s ease;  to img we  make that change  from bigger- to smaller look smooth, changing the 1s  to 1,1s will make the transition last longer and setting it to 0,9s will make it last shorter.

Enlarge Image on hover

In this example we just change the  height and width to be bigger rather than smaller. Compare the css with the first example above and you will understand what i mean.

Rotate Image on hover

In this example we have transition again but this time in  :hover instead of the image size we have  transform: rotate(360deg); which does exactly what it says – it rotates the image 360 degrees.

Tilt Image on hover

In this example the  360 is changed to 15 degrees so it just tilts a little bit.
Simple & Cool Live Examples of Image on hover Css effect

Now for the webkit browsers the effects are much more interesting, yet also very simple to create

Blur Image on hover

Again in the img we use the transition but this time in the :hover we have added a filter -webkit-filter: blur(5px); changing the 5px to more or less will change the blur strength.

Decolorize Image on hover

This time the filter is  -webkit-filter: grayscale(100%); again setting the100% to less will change the effect

Darken Image on hover

Here we have  -webkit-filter: brightness(100%); in img again as initial state and than by adding  -webkit-filter: brightness(0%); to :hover we trigger the change. and of course again you can set up the filters % to your needs.

Hue-rotate Image on hover

In this cool example we have added the filter -webkit-filter: hue-rotate(333deg); 


Drop shadow Image on hover

For drop shadow we use -webkit-filter: drop-shadow(10px 7px 1px grey)

Opacity Image on hover

In this last example we have  -webkit-filter: opacity(0.3); as a filter.
And that concludes my Image on hover Css effect article.

I suggest that you bookmark this page and use it as a starting point anytime you wish to practice and experiment.

You can also check some other cool stuff that i have about CSS.
If you like this article please be kind to share it on your favorite social networks below.

0 comments:

Post a Comment