Skip to content Skip to sidebar Skip to footer

Ignore/override Surrounding / Inherited CSS

I have this call to add HTML/CSS to an existing page: let div = document.createElement('div'); div.style.zIndex = 9999999; div.innerHTML = str; // some pre-defined HTML string doc

Solution 1:

Add a class to elements which you want to reset..and then apply all:unset to that class

The all CSS shorthand property sets all of an element's properties (apart from unicode-bidi and direction) to their initial or inherited values, or to the values specified in another style sheet origin.


...all:unset

Specifies that all the element's properties should be changed to their inherited values if they inherit by default, or to their initial values if not.(It will ignore all the user agent style too.)

Stack Snippet

let p = document.createElement('p');
p.style.color = "red";
p.innerHTML = "Hello"; // some pre-defined HTML string
p.classList.add("reset");
document.body.insertBefore(p, document.body.firstChild);
p {
  background: black;
}

.reset {
  all: unset;
}

Post a Comment for "Ignore/override Surrounding / Inherited CSS"