Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protect element from global css

My js is embedded on a third party website and it creates an <iframe> which contains a simple comments panel , but apparently on this specific website there is a CSS stylesheet which styles every <iframe> tag in the dom with the !important flag , so i can't change those css rules and the website dev team won't change this behaviour, there is another way to overcome this? can i change the tagname and still be an iframe? anything?

like image 207
avi dahan Avatar asked Sep 12 '25 20:09

avi dahan


1 Answers

You can use the all property with the initial value to default the styles for that element.

From the docs:

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

A code example:

#div-to-reset-styles {
  all: initial;
  * {
    all: unset;
  }
}

Just target your specific iframe and you should be fine.

like image 105
gd_silva Avatar answered Sep 14 '25 10:09

gd_silva