Copy the Code
In my opinion, the best way would be to actually extract what would be important from the code for you and then paste it into your code by adapting whatever is needed for your div. But there are two other ways to do this:
Iframe
There is the possibility of you creating a new page, say: div.html
and customize with the code from outside as if it were a new page and then simply pull it to your div, because then the page CSS will affect only what is inside the div and vice versa. I’d just put it like that on your div:
<div>
<iframe src="div.html"></iframe>
</div>
Style Scoped
This is not exactly an ideal way, as your support today is limited only to the Firefox, but I think it deserves a mention. There is this way where you write a new style where you want it on your page and it applies only in that region with the Scoped
. This way you could also import this CSS. Example:
<div>
<style scoped>
h1 { color: red; }
p { color: brown; }
</style>
<h1>Esse é um H1 afetado pelo scoped. Independente do estilo da página, ele será vermelho.</h1>
<p>Esse é um parágrafo na scoped div. O texto será marrom.</p>
</div>
<p>Esse parágrafo não será afetado e será preto.</p>
You could use it this way in your case:
<div>
<style scoped>
@import "externo.css";
</style>
</div>
Sources:
Any chance you could take what’s important from these CSS and put it on your targeting div site? I don’t recommend pulling external Csss that aren’t objective.
– Leon Freire
Div has a specific id or class?
– abfurlan
We’re already doing it, but there’s no easier and simpler way to do it than by erasing and testing?
– Miguel