Web browser hacks, Css hacks - ie, firefox, chrome, safri, Opera
CSS hacks take advantage of browser bugs for hiding CssRules from specific web browsers. Listed below are the hacks for major browsers like ie6, ie7, firefox2, firefox3, Google chrome, safari and opera.
Inline Hack for IE
* (star) can be used as the inline hack for both ie6 and ie7.
For Example:
Syntax: .selector{*property:value;}
.logo{*margin-left:10px;}
IE6 browser inline Hack
_ (underscore) can be using only for ie6
For Example:
Syntax: .selector{_property:value;}
.logo{_margin-left:10px;}
Firefox inline style
content:"\"/*" can be used for firefox only where IE cannot recognize it.
Internal Style
Use * html for ie6 and *+html hack for ie7
For Example:
Synatax: * html .selector{property:value;} , * + html .selector{property:value;}
* html .logo{margin-left:10px;} for ie6
* + html .logo{margin-left:20px;} for ie7
IE7 and Firefox browser Hack
Use html>body hack for ie7 and firefox.
For Example:
Syntax: html>body .selector{property:value;}
html>body .logo{margin-left:10px} will take only in ie7 and firefox
Mordern browser Hack or Firefox Hack
Use html>/**/body {} hack which will support only in both firefox2 and firefox3.
For Example:
Syntax: html>/**/body .selector{property:value;}
html>/**/body .logo{margin-left:10px} will take only in firefox.
Browser hack for Opera versions 9 and below
Use html:first-child {} for opera browser. Also you use
Syntax: @media all and (min-width:0px) {head~body .selector {property:value;}}
For Example:
@media all and (min-width:0px) {head~body .logo {margin-left:10px;}} only for opera
Firefox3 browser hack
Use html>/**/body .selector, x:-moz-any-link, x:default {property:value;} for firfox3 only.
For Example:
Syntax: html>/**/body .pro_yl, x:-moz-any-link, x:default {background:red;}
Google Chrome browser hack
Use body:nth-of-type(1) .elementOrClassName{property:value;} only for google chrome.
For Example:
body:nth-of-type(1) .logo{margin:20px;}
Safari browser hack
Use Syntax: body:first-of-type .elementOrClassName{property:value;}
Fox Example:
body:first-of-type .logo{margin-top:10px;} only for safari.
Hope this information will be useful for you. Please use the browser hacks in a proper manner. For example, you might know double margin bug in ie6. In such case you can use display inline which will render correctly by all the browsers instead of you using ie6 hack seperately.
Inline Hack for IE
* (star) can be used as the inline hack for both ie6 and ie7.
For Example:
Syntax: .selector{*property:value;}
.logo{*margin-left:10px;}
IE6 browser inline Hack
_ (underscore) can be using only for ie6
For Example:
Syntax: .selector{_property:value;}
.logo{_margin-left:10px;}
Firefox inline style
content:"\"/*" can be used for firefox only where IE cannot recognize it.
Internal Style
Use * html for ie6 and *+html hack for ie7
For Example:
Synatax: * html .selector{property:value;} , * + html .selector{property:value;}
* html .logo{margin-left:10px;} for ie6
* + html .logo{margin-left:20px;} for ie7
IE7 and Firefox browser Hack
Use html>body hack for ie7 and firefox.
For Example:
Syntax: html>body .selector{property:value;}
html>body .logo{margin-left:10px} will take only in ie7 and firefox
Mordern browser Hack or Firefox Hack
Use html>/**/body {} hack which will support only in both firefox2 and firefox3.
For Example:
Syntax: html>/**/body .selector{property:value;}
html>/**/body .logo{margin-left:10px} will take only in firefox.
Browser hack for Opera versions 9 and below
Use html:first-child {} for opera browser. Also you use
Syntax: @media all and (min-width:0px) {head~body .selector {property:value;}}
For Example:
@media all and (min-width:0px) {head~body .logo {margin-left:10px;}} only for opera
Firefox3 browser hack
Use html>/**/body .selector, x:-moz-any-link, x:default {property:value;} for firfox3 only.
For Example:
Syntax: html>/**/body .pro_yl, x:-moz-any-link, x:default {background:red;}
Google Chrome browser hack
Use body:nth-of-type(1) .elementOrClassName{property:value;} only for google chrome.
For Example:
body:nth-of-type(1) .logo{margin:20px;}
Safari browser hack
Use Syntax: body:first-of-type .elementOrClassName{property:value;}
Fox Example:
body:first-of-type .logo{margin-top:10px;} only for safari.
Hope this information will be useful for you. Please use the browser hacks in a proper manner. For example, you might know double margin bug in ie6. In such case you can use display inline which will render correctly by all the browsers instead of you using ie6 hack seperately.
Labels: css hacks, firefox 3.5, google chrome, ie, opera, safari, web browser hacks
FriendFeed
Twitter
Add to Favorites


46 Comments:
The hack for Chrome and Safari is now used to FF v.3.5.2, the new hack i used is:
@media screen and (-webkit-min-device-pixel-ratio:0)
{ #div { properties:value; } }
Thomaz Cia - thanks a lot! Just recently got complaints from FF 3.5 users, and now it's got fixed. Thanks!
Is there any hack only for Chrome or only for Safari not for both ot them, because I can't find solution that separate this browsers?
hi i need comman css for all browser using div tag
any hack for chrome should not detect by safari
Chrome :-
#mainNav li { margin:0 34px 0 0; }
@media screen and (-webkit-min-device-pixel-ratio:0) { /* hacked for chrome and safari */
#mainNav li { margin:0 26px 0 0; }
}
thanks but i use chrome hack it work but don't work in firefox
the hack for chrome also works in firefox. it overrides the hack meant for firefox. is there one that is only for chrome and only for firefox??
Use body:nth-of-type(1) .elementOrClassName{property:value;} only for google chrome.
Worked for me. Thankz...
cool post, like it. keep writing...
Hamid said: that is very usefull Hacks for all browsers
Inline Hack for IE doesn't work with ie8 :/
Thomaz Cia-Nice hack, Chrome and Safari was being bothersome this morning all of a sudden. Thanks
It is possible to target specific browsers in external .css file.
Example:
#middle {
font-size: .8em; //Opera all
* font-size: .7em; //IE6
//font-size: .7em; //IE 7, 8
}
/* FF only all*/
@-moz-document url-prefix() {
#middle {{font-size: .6em;}}
/* Safari all */
@media screen and (-webkit-min-device-pixel-ratio:0){
#middle{font-size: .6em;}}
!!! Keep order - and browsers never willl override code. Code is checked & proven many times. If browser doesn`t render code at once - you have to wait some time.
Professional webdesigner.
Mordern browser Hack or Firefox Hack
Use html>/**/body {} hack which will support only in both firefox2 and firefox3.
Unfortunately, this one affects IE8 too now
Opacity Hack:
#myElement {
opacity: .4; /* other browsers */
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); /* this works in IE6, IE7, and IE8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=40)"; /* this works in IE8 only */
}
This is great!!!! Thank you very very much!!!
Hack for ie8:
.test{
width:10px;
width:10px\0/; only for ie8
}
I've looking for this hack "width:10px\0/;" it helps me a lot thanks.
thanks for the post.
great info
I tried many of the Chrome specific hacks but the only one that worked for me (without affecting FF) was this one:
@media screen and (-webkit-min-device-pixel-ratio:0) { /* hacked for chrome and safari */
#mainNav li { margin:0 26px 0 0; }
}
It also affects Safari but, since they use the same rendering engine, it should work out just right. It did for me.
Thanks a lot......... Keep writing.......
Sorry but, I Think your Firefox hack is not working.
could you please mail me at (mkmishra19@gmail.com) with Firefox hack example
There is no fix for google chrome,just manage the css properly.
Chrome and firefox are almost same.
"just manage the css properly" - What does that mean exactly?
thanks.....
thanks but how to fix css in Google chrome?
U r ma time saver buddy... :)
all are good buddies
Thanks a lot for useful writing..
Not help much, but can fix little my blog, only I need code for IE, Firefox, Opera, Chrome. :D Thank.
i look for firefox 4+ hack please help
Thks, fixed CSS problem in google chrome
It seems to be very interesting about web browser hacks.U have made best post.Thanks for sharing !
web design company
this blog is very good,
thanks for solving my query.
thanks a lot ... you rock...
thanks
Good Blog..
wonderfull list of hacks. thx
Awesome Hacks site...:)
In regards to CSS, I am developing a website on a MAC OS operating system and when I view Chrome it looks fine, but when I view it on a PC via Chrome the CSS is off, any suggestions?
nice blog
Thanks for your post, you're a life saver! I'm one of the few people in my office who's really good with CSS, and everyone thinks I can solve everything lol. BTW, if anyone is still having problems targeting FireFox, I found the following hack to be useful:
@-moz-document url-prefix()
{
.editSelfUsernameEmail
{
text-align: right;
}
}
"Browser hack for Opera versions 9 and below
Use html:first-child {} for opera browser. Also you use
Syntax: @media all and (min-width:0px) {head~body .selector {property:value;}}
For Example:
@media all and (min-width:0px) {head~body .logo {margin-left:10px;}} only for opera"
toda essa parte o safari reconheçe e fica dando comflito com o opera.
There is obviously a lot to know about this. I think you made some good points in Features also
Post a Comment
Subscribe to Post Comments [Atom]
<< Home