Skip to main content

Amazing Hover Effects with CSS3


I have received a lot of questions lately about hover effects and how you can execute them using only CSS. There was a time when you would have to use jQuery to really make your effect stand out, but now CSS3 has some pretty amazing properties that help designers create some lightweight effects that truly stand out.

Box Shadow




This effect will create a shadow around your div container when you hover over it:
CSS:
div.shadow {
 width: 300px;
 margin: 20px;
 border: 1px solid #ccc;
 padding: 10px;
 }
 
div.shadow:hover {
 -moz-box-shadow: 0 0 5px rgba(0,0,0,0.5);
 -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.5);
 box-shadow: 0 0 5px rgba(0,0,0,0.5);
 }
HTML:
<div class="shadow">
Ut vulputate sem venenatis magna commodo ac semper nibh mollis. Pellentesque suscipit metus non lacus lacinia sed porttitor metus suscipit. Aenean egestas augue vel sem tincidunt scelerisque. Sed ullamcorper convallis arcu, vel euismod urna egestas in.
</div>
DEMO:
Ut vulputate sem venenatis magna commodo ac semper nibh mollis. Pellentesque suscipit metus non lacus lacinia sed porttitor metus suscipit. Aenean egestas augue vel sem tincidunt scelerisque. Sed ullamcorper convallis arcu, vel euismod urna egestas in.
That one’s pretty simple and straightforward, but still kind of cool. It can also be used on images.

Opacity

Having something fade in on a hover can be seen almost anywhere on the web.
CSS:
img.opacity {
 opacity: 0.5;
 filter: alpha(opacity=50);
 } 
 
img.opacity:hover {
 opacity: 1;
 filter: alpha(opacity=100);
 }
HTML:
<img src="http://bavotasan.com/wp-content/uploads/2011/01/spiral.jpg" width="550" height="366" alt="" class="opacity" />
DEMO:
If you want to create an even cooler opacity fade effect, you can take advantage of the new transition property. Note, this will only work in Webkit browsers such as Chrome and Safari.
CSS:
img.opacity {
 opacity: 0.5;
 filter: alpha(opacity=50);
  -webkit-transition: opacity 1s linear;
 } 
 
img.opacity:hover {
 opacity: 1;
 filter: alpha(opacity=100);
  -webkit-transition: opacity 1s linear;
 }
DEMO:
(this one only works in Chrome or Safari)

The Switch and/or Reveal

I have seen a lot of sites use an effect where something is revealed when you hover over an element. This one needs a bit more CSS and HTML since it requires two elements that sit on top of one another. I’m using text and an image in the example below but it can be two images, links or anything you want. Just remember that both elements need to use absolute positions or the effect will not work properly.
CSS:
div.top {
 margin: 20px 0;
 position: relative;
 width: 120px;
 height: 70px;
 border: 1px solid #aaa;
 overflow: hidden;
 } 
 
 div.top div {
  width: 100px;
  height: 50px;
  font-size: 12px;
  padding: 10px;
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  background: #fff;
  }
 
 div.top div.first {
  z-index: 1000;
  }  
 
div.top:hover div.first {
 display: none;
 }
HTML:
<div class="top">
 <div class="first">Hover over me to see something happen</div>
    <div class="second"><img src="http://bavotasan.com/wp-content/uploads/2011/01/happyface.jpg" alt="" height="50" width="50" /></div>
</div>
DEMO:
Hover over me to see something happen
The above example doesn’t use CSS3 since it is just taking advantage of the display property. Let’s see how CSS3 can make this effect stand out.
CSS:
div.top {
 margin: 20px 0;
 position: relative;
 width: 120px;
 height: 70px;
 border: 1px solid #aaa;
 overflow: hidden;
 } 
 
 div.top div {
  width: 100px;
  height: 50px;
  font-size: 12px;
  padding: 10px;
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  background: #fff;
     -webkit-transition: left 1s ease-in-out;
  }
 
 div.top div.first {
  z-index: 1000;
  }  
 
div.top:hover div.first {
 -webkit-transition: left 1s ease-in-out;
 left: -122px;
 }
DEMO:
Hover over me to see something happen
(this one also only works in Chrome or Safari)
You can have the slide work in any direction by either use the top property with a positive or negative number, or switching up the left property to use a positive number.

Position

A very simple effect that is often used on lists is to have the item slide over as your hover.
CSS:
ul.slide li:hover {
 padding-left: 5px;
 }
HTML:
<ul class="slide">
    <li><a href="http://bavotasan.com/downloads/my-first-vanilla-plugin/">My First Vanilla Plugin</a></li>
    <li><a href="http://bavotasan.com/downloads/delete-duplicate-posts-pro-wordpress-plugin/">Delete Duplicate Posts Pro WordPress Plugin</a></li>
    <li><a href="http://bavotasan.com/downloads/feed-me-seymour-free-wordpress-theme/">Feed Me, Seymour 1.2</a></li>
    <li><a href="http://bavotasan.com/downloads/magazine-basic-free-wordpress-theme/">Magazine Basic v2.6 WordPress Theme</a></li>
    <li><a href="http://bavotasan.com/downloads/sliderota-jquery-plugin/">Sliderota jQuery Plugin</a></li>
</ul>
DEMO:
Now let’s add some CSS3.
ul.slide li {
 padding-left: 0;
 -webkit-transition: all 0.5s ease-in-out;
 }
 
ul.slide li:hover {
 padding-left: 5px;
 -webkit-transition: all 0.5s ease-in-out;
 }
(once again this only works in Chrome or Safari)
Sadly, not all browsers are up to snuff in regards to CSS3, but as time passes most will release updates that take advantage of all the new properties and effects that have been released.

Comments

Popular posts from this blog

உடல் எடையை குறைக்க வேண்டுமா ?

இன்றைய அவசர உலகின் மிக பெரிய பிரச்சனையாக இருப்பது உடல் எடை அதிகரிப்பது தான்.மனம் போன போக்கில் உணவு கட்டு பாடு இல்லாமல் கண்டதையும் உள்ளே தள்ளுவதும்,உக்காந்த இடத்திலேயே கணணி முன் நேரத்தை விரயமாக்குவதும் தான் இந்த பிரச்சனைக்கு மூல காரணமாகும். அது சரி இந்த பிரச்சனையை எப்படி இல்லாமல் செய்வது அல்லது உடல் எடையை எவ்வாறு குறைப்பது என்பதை பற்றி பாப்போம் , பல வருட ஆரய்சிக்குபின் மருத்துவர்கள்   உடல் எடைய குறைக்க மிகவும் சுலபமான உடற்பயிற்சியை கண்டுபிடித்துள்ளனர்.இது  100% பயனளிக்க கூடியது, எந்த இடத்திலும் எந்தநேரத்திலும் மிக சுலபமா செய்ய கூடிய உடற் பயிற்சியாகும்.இந்த உடற்பயிற்சிகள் படத்துடன் கீழே தரப்பட்டுள்ளது நீங்களும் முயற்சித்து பாருங்கள கண்டிப்பாக பலன் கிடைக்கும்... முதலில் நாற்காலியில் உட்கார்ந்து இட  பக்கம் பார்கவும் .. ..        அடுத்து  நாற்காலியில் உட்கார்ந்து வல  பக்கம் பார்கவும்  ....  நண்பர்கள் யாரவது மச்சி வாடா சின்ன பீஸ் ,இங்க பாரு சூப்பர் அய்டம்னு சொல்லி கால்ல விழுந்து கூப்பிட்டலோ மேற்கூறிய உடற் பயி...

38 (new) web tools to keep you busy

For many of us, the internet represents our daily job, income resource or biggest hobby. Every day we check our emails, read our feeds, visit our websites, find and discuss new things and GOD knows what else. It requires a lot of tools to do all this stuff and sometimes, we forget to search for easier solutions losing valuable time or keeping down the production graph. It's very hard to keep track with everything that's new and popular and this is why we do monthly searches for the best web tools out there. Enjoy!  45+ Web Operating Systems "There are many more web operating systems hoping to bring all your usual desktop applications online in one place - here are more than 45 of our favorites."  15 Ways To Create Website Screenshots "15 Ways To Create Website Screenshots"  Open Source Windows "The promise of open source software is best quality, flexibility and reliability. The only way to have TRUE "Open Source Windows"is...

(Loot again) Get Mi Earphones & Mi Backpack In Just Rs.1

How to Get Mi Band , Mi Earphones & Mi Backpack In Just Rs.1 1, First Of All Just  Click On Below Links 1 By 1  Click 1->  Mi City Backpack Dark Grey Minimalist sleek design  -In Just Rs.1 Click 2->  Mi Earphones Silver Dynamic bass sound  -In Just Rs.1 2. Now Open All Links 1 By 1 3. After Opening The Link Click On “ Click to Bring The Price Down ” Then Click “ I Want it too ” 4. Login into Your Mi Account ( Or Sign Up  –  New Mi Account Giving Huge Price drop Like Rs.50 Or Rs.70 Drop , So Recommend You to Make New Account ) 5. Now You will See 3 Products There In this  Mi 24 Hour Madness Sale  6. Click On “ Participate ” Now Button & Share The Link With Your Friends When Each Friend Click On Your Link , You Will See Some Price cut in Your Products… Finally After Enough Click Your Product Will be Available For Just Rs.1  7. Start Referring , Start Looting MI