CSS Hack for Safari and Google Chrome
Posted by Asela de Saram in Browsers, CSS, CSS Hacks, Tips and TricksOne day I was coding this site and found that the elements aligned perfectly except for this annoying 1px difference that appeared only in Safari and Google Chrome. So after many hours of Googling and lots of Coffee, I foung this online.
This was my mis-behaving code:
#rightmasthead, #leftmasthead {
float:right;
text-align: right;
margin: 33px 0;
padding: 10px 15px 0 0;
border:0px solid #000;
width: 300px;
}
Personally, I try to avoid using CSS hacks, and when writing client code I always assume that anything can be done the “proper” way.
However, in most cases a hack is useful and needed, so here are two hacks (which are, in fact a valid CSS) that can be used to target and distinguish Google Chrome and Safari:
@media screen and (-webkit-min-device-pixel-ratio:0) {
#rightmasthead, #leftmasthead {
margin: 32px 0; /* This works only in Safari and Google Chrome */
}
}
Viola it works now perfectly!
If you enjoyed reading this post then please consider subscribing to my full RSS feed.




November 30th, 2009 at 7:54 am
Dear Author http://www.crystalaxis.com !
Good gradually.
June 13th, 2010 at 12:07 pm
Nice fill someone in on and this mail helped me alot in my college assignement. Thank you for your information.