Posted By

reverend on 09/20/11


css js browser detect target boilerplate

Versions (?)

Target specific browsers in CSS with JS

 / Published in: JavaScript


Will produce output like this:



Target in CSS like this:

html[data-useragent*='Chrome/13.0'] .nav {background:url(img/radial_grad.png) center bottom no-repeat;}


html[data-useragent*='Chrome/13.0'][data-platform='Win32'] {}

or iPad only html[data-platform='iPad']

  1. <script>
  2. var b = document.documentElement;
  3. b.setAttribute('data-useragent', navigator.userAgent);
  4. b.setAttribute('data-platform', navigator.platform );
  5. </script>

Report this snippet  

You need to login to post a comment.