I have to integrate my webpage code into a big project. Entire project code is inside container div which is included inside <main>
tag. When I add the container div in <main>
tag, the project css overwrites my css. Is there a way where we can write a div that creates its own css environment and stops from outside css affecting inner tags?
Asked
Active
Viewed 988 times
2
-
1like a reset css? #yourdivid * { /* reset all css here */ } – Chris Li Sep 13 '18 at 06:39
-
div {all: unset; other_properties: and_values; ... (of your choice)} – VXp Sep 13 '18 at 06:53
2 Answers
2
Option 1: iframe will scope your html, but you will not be able to access dom.
Option 2:
reset CSS with
.your-div{
all: initial;
* {
all: unset;
}
}

segu
- 321
- 2
- 12
0
You can use an iframe with the srcdoc attribute. Things inside an iframe are immune to outside css!
iframe {display:block; border:none}
/* css to demonstrate the immune div */
div {color:red; background:yellow; border:solid;}
<div>This is a standard div</div>
<iframe srcdoc="<div>This is a framed div, immune to css</div>"></iframe>
See <iframe>
on MDN for more info and pitfalls.

Mr Lister
- 45,515
- 15
- 108
- 150