Skip to content

Instantly share code, notes, and snippets.

@dieulot
Last active June 30, 2020 04:36
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dieulot/520a49463f6058fbc8d1 to your computer and use it in GitHub Desktop.
http://dieulot.net/css-retina-hairline – CSS retina hairline, the easy way – JS
if (window.devicePixelRatio && devicePixelRatio >= 2) {
var testElem = document.createElement('div');
testElem.style.border = '.5px solid transparent';
document.body.appendChild(testElem);
if (testElem.offsetHeight == 1)
{
document.querySelector('html').classList.add('hairlines');
}
document.body.removeChild(testElem);
}
// This assumes this script runs in <body>, if it runs in <head> wrap it in $(document).ready(function() { })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment