Skip to content

Instantly share code, notes, and snippets.

@dmitryshimkin
Last active December 15, 2015 18:19
Show Gist options
  • Select an option

  • Save dmitryshimkin/5303410 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryshimkin/5303410 to your computer and use it in GitHub Desktop.
Less mixin to emulate :focus pseudo-class for IE7. Probably works under IE 5-6 (not tested). Based on one-time expression (executed only once, doesn't affect performance)
/* mixin */
.focus(@className: "focused") {
behavior: ~"expression(function focus(el) { el.runtimeStyle.behavior = 'none'; var focusClass = ' @{className}'; el.onfocus = function() { el.className += (focusClass); }; el.onblur = function() { el.className = el.className.replace(new RegExp(focusClass, 'g'), ''); }; }(this))";
}
/* usage */
.input {
.focus("input_focused");
.input:focus,
.input_focused {
border-color: blue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment