My original solution to that problem was a Javascript hack that inserts a couple of 1 pixel wide divs at the edge of any element with a shadow class. However, although I have tweaked it several times, it has always been a bit slow. For instance, for the shop front page we're currently rendering more than 60 elements with shadows which takes a couple of seconds with Firefox and Firebug on my old trusty PIII 950 MHz laptop. I'll note that this is actually an order of magnitude faster than the (more general) code I based it on from somewhere else. The really tricky part was decent-speed IE 6 support because that actually required measuring the DOM elements.
However, Firefox 3.5 was released about a month ago, and one of the good news was support for the
box-shadow
CSS3 property. It's a relatively simple property for adding drop shadows. So given that Safari has it, and has had for some time, and most Firefox users will soon have it, it starts getting interesting. For reference, about half of our visitors are Firefox + Safari (+ Chrome which uses the same rendering engine as Safari).If you search for
box-shadow
, some are already using it to add a bit of extra embellishment. However, on YayArt, it's an integrated part of the design. So I had to figure out how to make it work on all browsers.I ended up with a three-way solution. For recent Firefox/Safari/... I use
box-shadow
. For non-box-shadow
supporting browsers, I fallback to the old hack. And for Internet Explorer, I'm using a new hack based on the proprietary filter stuff in IE.Here's a quick sketch. I put this in the general stylesheet:
.shadowed { -moz-box-shadow: 2px 2px 3px #969696; -webkit-box-shadow: 2px 2px 3px #969696; }This makes it work with browsers based on the Gecko and Webkit engines. Some people recommend adding a plain
box-shadow
line, but I need full control over which browsers are responding, and besides it seems to defeat the purpose of the browsers using the -engine-
prefix. Here's a demo:If your browser is recent enough, you can see a shadow here.
Now for the fallback, I need to discover in Javascript whether the browser is using the CSS:
function supportsBoxShadow() { var s = document.body.style; return s.WebkitBoxShadow !== undefined || s.MozBoxShadow !== undefined; }The assumption is that the symbols will be defined only if the browser actually draws the shadow. This seems to be about right, the only exception I've found so far is the Webkit port to GTK (there's a bug report open).
Final point is Internet Explorer. As it turns out, there is a DropShadow filter. It's not terrible useful for this purpose, however. There are no soft edges, and it shadows the content rather than the containing box (it simply redraws the content with an offset in another color). So for my purpose I need to set a background color to ensure it's drawing a rectangle and not a text shadow. You could probably hack the lack of blurring with another filter, but in the end I went with a simple three-one-pixel-wide-lines approach that looks like my old hack but is much faster (updated, replaced the filter with a more appropriate one as suggested in the comments):
.shadowed { background-color: #fff; zoom: 1; filter: progid:DXImageTransform.Microsoft.Shadow(color='#969696', Direction=135, Strength=3); }This is served for IE only. The
zoom: 1
is a hack to ensure that the element gets a layout (to work around the usual IE 6 bug).So there you have it. Practical drop shadows. I will have to adjust the code a little bit as the other browsers get support, but I can live with that.
Man, this is amazing!!! Realy amazing!!! This is the best solution and work´s fine!!!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI like to use this in my website
Deletewww.visitorbazaar.com
May I use?
Good, but Opera 10.10 (current 21/01/2010) fails
ReplyDeleteOnly Opera 10.50 alpha wins
thanks a lot
pixelzero: You still need another hack for old browsers. I didn't document that hack here, I only explained how to discover that you need it. :)
ReplyDeleteI have one in action on YayArt.com, but it's a little bit complicated and has some caveats.
i have found the scripts for Opera from 9.5 (to the 10.50 version at this time) in your code (the common js).
ReplyDeletenow i'm trying to apply to mupeditore.it
thanks a lot
ReplyDeletefilter: progid:DXImageTransform.Microsoft.Shadow(color='#777777', Direction= 135, Strength=8);
yes, cool, only one line make the same of eights
Yeah, switching
ReplyDeletefilter:
progid:DXImageTransform.Microsoft.DropShadow(color=#969696, offx=1, offy=1)
progid:DXImageTransform.Microsoft.DropShadow(color=#C2C2C2, offx=1, offy=1)
progid:DXImageTransform.Microsoft.DropShadow(color=#EFEFEF, offx=1, offy=1);
out with
filter: progid:DXImageTransform.Microsoft.Shadow(color='#969696', Direction=135, Strength=3);
I'll update the blog post. Thanks!
Hmmm, oddly enough your example doesn't work in IE 7 or IE 8 on my xp or vista installs. Just shows a grey box with no shadow.
ReplyDeleteworks for me,
ReplyDeleteXP sp3 ie8 and ie 7 & 6 with IETester
You could also do this to generate a rounded box-shadow ;)
ReplyDeletehttp://blog.citycrawler.com/?p=103
- Daniel
this is awesome!
ReplyDeletethanks!
Lovely trick indeed. Unfortunately does not work well with elements positioned absolutely that has :hover applied to it... Any thoughts to a fix guys?
ReplyDeleteto other not working try to put "!important" in css
ReplyDeletefilter: progid:DXImageTransform.Microsoft.Shadow(color='#969696', Direction=135, Strength=3) !important;
Hi,
ReplyDeleteI'd recommend checking out http://www.modernizr.com/ . This is a great tool to determine not just the browser but specific browser functions like if it supports box-shadow. Than you have access to a class: .no-boxshadow to apply rules for browsers that don't support box-shadow.
:Sam
works fine you make my day!
ReplyDeleteThanks Ole!
ReplyDeleteIt doesn't work in ie8 compat mode - but better than nothing. Looks good in ie6 too... Yes some of my target audience may still be using this...
Awesome fix! Thx a lot!
ReplyDeleteWOW! It's realy best solution that i saw.
ReplyDeleteThx u!
Thanks.. working fine....
ReplyDeletethnxx
ReplyDeleteoh! just i was trying drop shadow to my input box, but i did not get solution for IE browser, my luckily i found solution in your website. Thanks for posting.
ReplyDeleteCan i post same article to my blog. see this my blog: http://www.addcolours.com/blog
This solution is not working on IE 8
ReplyDeleteThank you so much!
ReplyDeleteNot working in IE8 on xp.
ReplyDeleteIE 8: it seems to work for me, when I visit YayArt with my IE 8 on Windows XP, I definitely get shadows.
ReplyDeleteAs one of the above comments mention, it may not work in IE 8 compatibility mode, I think this may be fixable, but really, you should get out of that mode as soon as possible because it means you're stuck with the old non-standard compliant renderer.
I still can't get this to work in IE9, I will try creating a sector just for IE.
ReplyDeleteDon't use the IE hack for IE9, it has native support for box-shadow: http://msdn.microsoft.com/en-us/library/cc351024(v=vs.85).aspx
ReplyDeleteCheck out css3pie.com. It uses methods similar to this for many css3 styles in IE, and works really well, all things considered.
ReplyDeletecss3pie is not work correct find curvecorner script and put ur site.and should must -moz-border-radius:10px;
DeleteYou should still put the standard box shadow call below the -moz & -webkit so that when a browser fully adds the box shadow capability you are overriding the workaround (-moz and -webkit)
ReplyDeleteits work friend. tq, i like this
ReplyDeleteHad to switch it off on the shadowed content as the contained link hover states became unresponsive:
ReplyDelete.shadowed * {filter:none}
hre provide all ie solution.like box shadow,corner,text shadow.
ReplyDeleteand here also provide jquery script for box shadow,text shadow because it solution is not work in IE. so plz provide.
ReplyDeleteGREAT JOB SIR
ReplyDeleteThank you....
ReplyDeleteFinally.. thanks man!
ReplyDeleteno shadow or round corner in ie9..... but css3 worked good at mozila, chrome, safari, opera, firefox.....
ReplyDeletefuck ie9.
Thank for share this great trick
ReplyDeleteIE9 supports box-shadow so you can stop moaning about that.
ReplyDeleteFor IE6,IE7,IE8
ReplyDeletefilter: progid:DXImageTransform.Microsoft.Shadow(color='#777777', Direction= 135, Strength=8);
zoom: 1;
But there is a problem cursor in area input box to apply with css filter.
The cursor will display wrong position in input box when you key press them.
Anybody know how to fixed ? Thanks....
görüntülüshow
ReplyDeleteücretli show
RUF8X
ığdır evden eve nakliyat
ReplyDeletebitlis evden eve nakliyat
batman evden eve nakliyat
rize evden eve nakliyat
niğde evden eve nakliyat
1FDMDZ
karabük evden eve nakliyat
ReplyDeletebartın evden eve nakliyat
maraş evden eve nakliyat
mersin evden eve nakliyat
aksaray evden eve nakliyat
BLGB37
urfa evden eve nakliyat
ReplyDeletemalatya evden eve nakliyat
burdur evden eve nakliyat
kırıkkale evden eve nakliyat
kars evden eve nakliyat
2T2HBP
737D0
ReplyDeleteÇorum Parça Eşya Taşıma
Ankara Lojistik
Rize Şehir İçi Nakliyat
Ağrı Şehirler Arası Nakliyat
Artvin Lojistik
Paribu Güvenilir mi
Kilis Şehir İçi Nakliyat
Antalya Lojistik
İstanbul Şehir İçi Nakliyat
55F3E
ReplyDeleteKars Şehirler Arası Nakliyat
Burdur Evden Eve Nakliyat
Karabük Parça Eşya Taşıma
Hakkari Şehirler Arası Nakliyat
Karabük Şehirler Arası Nakliyat
Trabzon Evden Eve Nakliyat
Denizli Parça Eşya Taşıma
Amasya Lojistik
Diyarbakır Şehirler Arası Nakliyat
CC62F
ReplyDeleteAksaray Lojistik
primobolan
Niğde Şehirler Arası Nakliyat
Kastamonu Parça Eşya Taşıma
testosterone propionat
Kırklareli Şehir İçi Nakliyat
Antep Lojistik
fat burner for sale
Niğde Evden Eve Nakliyat
B2BBC
ReplyDeleteOkex Borsası Güvenilir mi
Kripto Para Kazanma Siteleri
Bitcoin Nasıl Oynanır
Coin Nasıl Kazılır
Coin Kazanma
resimli magnet
Bitcoin Madenciliği Siteleri
Coin Kazma Siteleri
Kripto Para Madenciliği Siteleri
EFC6C
ReplyDeleteCoin Madenciliği Nedir
Coin Çıkarma
Coin Madenciliği Siteleri
Bitcoin Yatırımı Nasıl Yapılır
Bitcoin Madenciliği Siteleri
Coin Nasıl Oynanır
Binance Madenciliği Nedir
Bitcoin Kazanma
Binance Nasıl Üye Olunur
BCDB8
ReplyDeleteBtcturk Borsası Güvenilir mi
Kripto Para Nasıl Üretilir
Binance Kimin
Ön Satış Coin Nasıl Alınır
Bitcoin Nasıl Para Kazanılır
resimlimag.net
Coin Oynama
Binance Ne Kadar Komisyon Alıyor
Mexc Borsası Kimin
E3C74
ReplyDeleteRESİMLİ MAGNET
50F6E
ReplyDeletecanli sohbet
referans kimligi nedir
kripto para nasıl alınır
toptan sabun
https://kapinagelsin.com.tr/
poloniex
bybit
binance referans kod
bitexen
EE46E
ReplyDeletetelegram kripto kanalları
paribu
mercatox
kripto para nasıl alınır
canli sohbet
gate io
4g proxy
kripto para telegram grupları
kucoin
5D171
ReplyDelete----
matadorbet
----
----
----
----
----
----
----
D8E93
ReplyDeletematadorbet
----
----
----
----
----
----
----
----
zxcfddgdsfgrt
ReplyDeleteصيانة افران
رقم مصلحة المجاري بالاحساء zzbu4Fol1L
ReplyDeleteشركة عزل اسطح بالرياض HZQGBrhHRV
ReplyDeleteشركة تسليك مجاري بالاحساء 5tqJQ9bHGw
ReplyDeleteرقم مصلحة المجاري بالاحساء QVnEzk7uBs
ReplyDeleteشركة تنظيف مجالس بالدمام 7VTkX2NBjA
ReplyDeleteشركة عزل اسطح بالمدينة المنورة hprLyOPUVS
ReplyDelete