How to apply specific CSS rules to Chrome only?

user1213707 picture user1213707 · Feb 17, 2012 · Viewed 253.6k times · Source

Is there a way to apply the following CSS to a specific div only in Google Chrome?

position:relative;
top:-2px;

Answer

Martin Kristiansson picture Martin Kristiansson · Nov 27, 2012

CSS Solution

from https://jeffclayton.wordpress.com/2015/08/10/1279/

/* Chrome, Safari, AND NOW ALSO the Edge Browser and Firefox */
@media and (-webkit-min-device-pixel-ratio:0) {
  div{top:10;} 
}

/* Chrome 29+ */
@media screen and (-webkit-min-device-pixel-ratio:0)
  and (min-resolution:.001dpcm) {
    div{top:0;} 
}

/* Chrome 22-28 */
@media screen and(-webkit-min-device-pixel-ratio:0) {
  .selector {-chrome-:only(; 
     property:value;
  );} 
}

JavaScript Solution

if (navigator.appVersion.indexOf("Chrome/") != -1) {
// modify button 
}