Last active
October 28, 2022 02:47
-
-
Save ujiro99/c86ea308766ee6e3f6190091d09ee15f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const content = ` | |
<style> | |
:host { | |
--ul-color-1: green; | |
} | |
div { | |
border: 1px solid #ccc; | |
padding: 1rem; | |
color: red; | |
font-family: sans-serif; | |
} | |
.list-1 { | |
color: var(--ul-color-1, black); | |
} | |
.list-2 { | |
color: var(--ul-color-2, black); | |
} | |
.list-3 { | |
color: var(--ul-color-3, black); | |
} | |
</style> | |
<div> | |
Element with Shadow DOM.<br> | |
<ul> | |
<li class="list-1">A child element 1.</li> | |
<li class="list-2">A child element 2.</li> | |
<li class="list-3">A child element 3.</li> | |
</ul> | |
</div> | |
`; | |
const hosts = document.querySelectorAll(".shadow-host"); | |
hosts.forEach((el) => { | |
const shadow = el.attachShadow({ | |
mode: "closed" | |
}); | |
shadow.innerHTML = content; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellat odit officiis necessitatibus laborum asperiores et adipisci dolores corporis, vero distinctio voluptas, suscipit commodi architecto, aliquam fugit. Nesciunt labore reiciendis blanditiis!</p> | |
<div class="shadow-host" style="--ul-color-3: orange;"> | |
<!-- Also could be a | |
<custom-element /> | |
--> | |
</div> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellat odit officiis necessitatibus laborum asperiores et adipisci dolores corporis, vero distinctio voluptas, suscipit commodi architecto, aliquam fugit. Nesciunt labore reiciendis blanditiis!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.shadow-host { | |
--ul-color-2: blue; | |
margin: 0 0 1rem 0; | |
} | |
body { | |
max-width: 400px; | |
margin: 1rem auto; | |
padding: 0 1rem; | |
font-family: "comic sans ms"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment