Skip to content

Instantly share code, notes, and snippets.

@bofrede
Last active May 3, 2018 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bofrede/3b9fcdf80b3cfbf848981e845a97aa61 to your computer and use it in GitHub Desktop.
Save bofrede/3b9fcdf80b3cfbf848981e845a97aa61 to your computer and use it in GitHub Desktop.
Disable all styles in a @supports rule.
function disable_support(supports_condition) {
for (var si = 0; si < document.styleSheets.length; si++) {
window.console.log("Looking in " + document.styleSheets[si].href);
var rules = document.styleSheets[si].cssRules;
for(var i = 0; i < rules.length; i++) {
if (rules[i].type === 12 && rules[i].conditionText.match(supports_condition)) {
window.console.log("Removing style index " + i);
document.styleSheets[0].deleteRule(i);
}
}
}
}
// To disable rules inside: @supports (display:grid) {
function disable_grid_support() {
disable_support("(\s*display\s*:\s*grid\s*)");
}
// To disable rules inside: @supports (display:flex) {
function disable_flex_support() {
disable_support("(\s*display\s*:\s*flex\s*)");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment