Css: Image Hover Effects You Can Copy and Paste

CSS: Image Hover Effects You Can Copy and Paste
by Janeth Kent Date: 09-04-2014 css3 effects web design


In the past, we’ve wrote about some awesome examples of CSS effects that were easy to copy and paste right into your code.

Today, we’re going to follow that up with ten new effects specifically built for use with images. Each example comes with an HTML and CSS snippet.

1. Sneak Peek

Before we begin creating the individual demos, some basic setup is required. Here’s a chunk of CSS that we’ll be using to dictate the basic appearance of all of the examples.




  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
      -ms-box-sizing: border-box;
          box-sizing: border-box;
}
 
body {
  background: #333;
}
 
.pic {
  border: 10px solid #fff; 
  float: left;
  height: 300px;
  width: 300px;
  margin: 20px;
  overflow: hidden;
   
  -webkit-box-shadow: 5px 5px 5px #111;
          box-shadow: 5px 5px 5px #111; 
}

 

Box-sizing allows you to manipulate the box model, and the pic class gives us a place to toss in some generic styling for each photo.

2. Zoom and Pan

The first group of effects involves utilizing some tricks with hidden overflow. By clipping the image to the bounds of a div, we can pull off some pretty cool hovers.

To begin, we’ll make it so that when the user hovers over the image, the photo enlarges while still staying within its bounds, resulting in a zooming in effect. Here’s the HTML.

HTML



<div class="grow pic">
  <img src="http://yoururl.com/assets/img" alt="portrait">
</div>

Now let’s see the CSS.


/*GROW*/
.grow img {
  height: 300px;
  width: 300px;
 
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.grow img:hover {
  width: 400px;
  height: 400px;
}

3. Shrink

We’ve seen how to grow an image on hover, so let’s reverse that effect and zoom the photo out. The method is pretty much exactly the same, only this time you’ll start with the size at 400px and shrink it to 300px on hover.

HTML

<div class="shrink pic">
<img src="http://yoururl.com/assets/img" alt="city">
</div>

CSS


/*SHRINK*/
.shrink img {
  height: 400px;
  width: 400px;
 
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.shrink img:hover {
  width: 300px;
  height: 300px;
}

4. Side Pan

The next effect keeps the image the same size throughout, but pans it sideways as the user hovers.

CSS


<div class="sidepan pic">
  <img src="http://yoururl.com/assets/img" alt="kick">
</div>

HTML

/*SIDEPAN*/
.sidepan img {
margin-left: 0px;
-webkit-transition: margin 1s ease;
-moz-transition: margin 1s ease;
-o-transition: margin 1s ease;
-ms-transition: margin 1s ease;
transition: margin 1s ease;
}

.sidepan img:hover {
margin-left: -200px;
}

For the pan, we're not changing the image size like we did last time, but instead using margin to pull the image left on hover. If you want it to move right, use a positive value or margin-right.

5. Vertical Pan

We use this effect to convey a sense of motion, but this is also great for communicating height if you want to pan up something like a tall building.

CSS


<div class="vertpan pic">
  <img src="http://yoururl.com/assets/img" alt="climb">
</div>

HTML


/*VERTPAN*/
.vertpan img {
  margin-top: 0px;
  -webkit-transition: margin 1s ease;
     -moz-transition: margin 1s ease;
       -o-transition: margin 1s ease;
      -ms-transition: margin 1s ease;
          transition: margin 1s ease;
}
 
.vertpan img:hover {
  margin-top: -200px;
}

6. Tilt

This one is super simple, all we're going to do is rotate the image slightly when the user hovers over it. The result is a basic but fun illusion of a crooked hanging picture.

HTML


<div class="tilt pic">
  <img src="http://yoururl.com/assets/img" alt="car">
</div>

CSS



/*TILT*/
.tilt {
  -webkit-transition: all 0.5s ease;
     -moz-transition: all 0.5s ease;
       -o-transition: all 0.5s ease;
      -ms-transition: all 0.5s ease;
          transition: all 0.5s ease;
}
 
.tilt:hover {
  -webkit-transform: rotate(-10deg);
     -moz-transform: rotate(-10deg);
       -o-transform: rotate(-10deg);
      -ms-transform: rotate(-10deg);
          transform: rotate(-10deg);
}

 

7. Morph

When the user hovers, the image begins to spin. As it spins, it morphs from a square into a circle. The result is super fun to play with.

HTML

<div class="morph pic">
  <img src="http://yoururl.com/assets/img" alt="beach">
</div>




CSS

/*MORPH*/
.morph {
  -webkit-transition: all 0.5s ease;
     -moz-transition: all 0.5s ease;
       -o-transition: all 0.5s ease;
      -ms-transition: all 0.5s ease;
          transition: all 0.5s ease;
}
 
.morph:hover {
  border-radius: 50%;
  -webkit-transform: rotate(360deg);
     -moz-transform: rotate(360deg);
       -o-transform: rotate(360deg);
      -ms-transform: rotate(360deg);
          transform: rotate(360deg);
}



What I’ve done here is set the morph class to spin 360 degrees on hover. As it’s spinning, the border-radius will gradually climb its way to 50%, resulting in a circle.

8. Focus

Here’s another effect that uses border-radius to round off the image. This time, we’ll not only increase the border’s radius but also its thickness. Combined with the border-box, this will create an effect that focuses in on on particular part of an image.

HTML

<div class="focus pic">
    <img src="http://yoururl.com/assets/img" alt="cricket">
  </div>




CSS

/*FOCUS*/
.focus {
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.focus:hover {
  border: 70px solid #000;
  border-radius: 50%;
}



What I did here was take our 10px white border and turned it into a 70px black border while cranking the radius up to 50% like we did in the last example.

 

Webkit Filters

This last set of effects is purely experimental. Unlike the examples above, all of which use multiple prefixes to ensure maximum browser compatibility, these only use the -webkit prefix because there’s no other support at the moment. If you’re not using Safari or Chrome, these aren’t going to work for you.

Despite the unfortunate constraints, Webkit filters let you perform some pretty awesome effects! Here’s a demo of three of my favorites:

9. Blur

The first effect that we’re going for is a simple blur.

HTML

 <div class="blur pic">
http://yoururl.com/assets/img" alt="plane">
</div>




CSS

/*BLUR*/
.blur img {
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.blur img:hover {
  -webkit-filter: blur(5px);
}



AS you can see, we use the -webkit-filter property, then set the blur to 5px.

10. B&W

This time we’re going to drop all of the saturation out of the image on hover. It used to take two images to pull off this effect but with Webkit filters, we can cut this down to one.

HTML

 <div class="blur pic">
http://yoururl.com/assets/img" alt="plane">
</div>




CSS

/*B&W*/
.bw {
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.bw:hover {
  -webkit-filter: grayscale(100%);
}



11. Brighten


For our final trick, we’re going to darken a photo by default, then brighten it up to its normal state on hover. This creates a sort of reveal effect.

 <div class="brighten img">
http://yoururl.com/assets/img" alt="plane">
</div>



/*DARKEN*/
.brighten img {
  -webkit-filter: brightness(-65%);
  -webkit-transition: all 1s ease;
     -moz-transition: all 1s ease;
       -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
          transition: all 1s ease;
}
 
.brighten img:hover {
  -webkit-filter: brightness(0%);
}



Here, 0% is regular brightness. Anything above that and you brighten the image, anything below and you darken it. We started at -65% and brought it up to 0% on hover.

 

 

 

 
by Janeth Kent Date: 09-04-2014 css3 effects web design hits : 14220  
 
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN END DEVELOPMENT.

 
 
 

Related Posts

Understanding LCP, CLS, FID. All about Core Web Vitals in Google Search Console

A few months ago we talked about certain Google metrics that were displayed in Search Console. The reason for writing another post on this topic is that Google has changed…

Validating HTML forms using BULMA and vanilla JavaScript

Today we are going to write about contact forms and how to validate them using JavaScript. The contact form seems to be one of the top features of every basic home…

How to use Parallax.js effect on your website

Today, we're going to write about the parallax effect, similar to parallax scrolling, and how to implement it to improve your landing page. In webdev, they say mobile first -…

How to make the website's dark mode persistent with Local Storage, CSS and JS

Recently we wrote about how to do a switchable alternative color mode or theme, a very useful and popular feature to websites. Today’s article is going to be about how…

Dark Web: the creepy side of the Internet is not as dark as believed

People who surf the Dark Web are not necessarily looking for something illegal. Most people want to protect their privacy. And according to a recent study, 93 percent only use…

Cross cultural challenges in web design, an overview

The user experience design of a product essentially lies between the intentions of the product and the characteristics of your user. - David Kadavy - The task of building a culturally appropriate…

Website Traffic Getting Low? 4 Immediate Action to Take

If you have created a website, I am sure your end objective is to create a strong brand presence, boost engagement, and multiply revenue. An interesting statistic showed that there were…

The easiest way to align items using flexbox

With the release of flexbox in CSS, it has become an essential tool when placing elements next to each other, since, by default, the children of a display: flexare stacked…

Dark Mode on website using CSS and JavaScript

In today’s article we are going to learn how to build pretty much standard these days on the web pages and that is the alternative color mode and switching between…

JavaScript: Spread and Rest operators

In today’s article we are going to talk about one of the features of the ES6 version(ECMAScript 2015) of JavaScript which is Spread operator as well as Rest operator. These features…

How To Add Filter Effects to Images with CSS

To achieve interesting effects on your images, learn about the 'filter' and 'Backdrop-Filter' properties of CSS. CSS filters are a very attractive feature of CSS that allows you to apply certain…

Why You Should Hire Node.js Developer for Your Backend Development

When developers are building a new website, they mainly focus on both frontend and backend development. The frontend code helps create the interfaces through which the app interacts with the…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration