Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2010, 03:37 PM   PM User | #1
geekygirl
New Coder

 
Join Date: Nov 2010
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
geekygirl is an unknown quantity at this point
help with rollover drop shadow in CSS

I'm trying to get a drop shadow on an image but only when I roll over it. I didn't want to have to do the whole adding a second image with a drop shadow from photoshop thing. I read up on tutorials about adding drop shadows in just CSS but I'm no expert and therefore I'm not sure how I would implement that into just a roll over effect. Any ideas?
geekygirl is offline   Reply With Quote
Old 11-16-2010, 04:09 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
The css property is box-shadow. It's a bit messy adding it in css, because a number of browsers support it only with browser specific extensions.
So, to add it on hover:

Code:
img:hover {
-moz-box-shadow:3px 3px 3px rgba(0,0,0,0.7);
-webkit-box-shadow:3px 3px 3px rgba(0,0,0,0.7);
box-shadow:3px 3px 3px rgba(0,0,0,0.7);
}
So the first line sorts FF3, the second Chrome and Safari, and the fourth Opera 10.6+ and IE9. You'll spot the missing browser there, IE8 and under, which don't support it via css, although there are some javascript options.

I should add that this is setting a 3px horizontal offset, a 3px vertical offset, a 3px blur distance, a black colour - rgba(0,0,0) - and 0.7 opacity. I used this as I think it's a nice effect. Obviously you can change to what you want.

Last edited by SB65; 11-16-2010 at 05:07 PM..
SB65 is offline   Reply With Quote
Old 11-16-2010, 04:44 PM   PM User | #3
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
Is this a square image? If so you could wrap it in a div, set a dark color to the div and then give it offset margins to give the appreance of a drop shadow.

Didnt see the rollover requirements...lol but still could be done I would think using hover.
teedoff is offline   Reply With Quote
Old 11-17-2010, 02:19 PM   PM User | #4
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello geekygirl,
It would be pretty easy to just use a border to look like a drop shadow. Like this example.
You would need to make the normal state have no color on the border and then color the hovered state.
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Old 09-23-2011, 08:26 AM   PM User | #5
gabriella28
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
gabriella28 is an unknown quantity at this point
Thank you very much, your solution and advice worked and helped me!!!
gabriella28 is offline   Reply With Quote
Reply

Bookmarks

Tags
css, image, roll over

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:37 AM.


Advertisement
Log in to turn off these ads.