Published
Edited
Dec 24, 2020
20 stars
Insert cell
Insert cell
function shadowRoot(el) {
const shadowRoot = el.attachShadow({mode: "open"});
while (el.firstChild) shadowRoot.appendChild(el.firstChild);
return el;
}
Insert cell
shadowRoot(html`<div>Hello! Content with a fancy CSS.</div><style>div { background: #fefe88 }</style>`)
Insert cell
shadowRoot(
html`<div>Hello! Content with another fancy CSS.</div><style>div { background: brown; color: white; }</style>`
)
Insert cell
html`<div>This div is unaffected by the CSS inside any of the shadow roots.</div>`
Insert cell
Insert cell
shadowRoot(
html`<div class="change">This .change div will use the global stylesheet
<style>.change { font-style: italic; }</style>
</div>`
)
Insert cell
shadowRoot(
html`<div><!-- wrapper -->
<div class="change">This .change div will use the shadow stylesheet
<style>.change { font-style: italic; }</style>
</div>`
)
Insert cell
html`<style>.change { font-variant: small-caps }`
Insert cell
Insert cell
shadowRoot(html`<div><style>
:host {background: coral; width: 200px; height: 100px; border-radius: 10px}
`)
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more