Testing the Shadow DOM
by mdvanes
HTML
<div class="custom-old">
<h3>Normal</h3>
<p>This is in the normal DOM</p>
</div>
<div class="custom-new"><h1>test</h1></div>
<x-foo></x-foo>
Custom color play button:<br/>
<video src="http://mdworld.nl/cms/themes/simon/video/MDE_Leader-web-no_audio.ogv" controls="true"></video>
SCSS
.custom-old {
$color: #ff0099;
border: 1px solid $color;
border-radius: 2px;
font: 14px Arial;
margin-bottom: 1em;
padding: 1em;
width: 200px;
h3 {
color: $color;
text-transform: uppercase;
}
p {
background-color: $color;
color: white;
padding: 0.5em;
}
}
.custom-new, x-foo {
$color: #9900ff;
&::shadow {
div {
border: 1px solid $color;
border-radius: 2px;
font: 14px Arial;
margin-bottom: 1em;
padding: 1em;
width: 200px;
}
h3 {
color: $color;
text-transform: uppercase;
}
p {
background-color: $color;
color: white;
padding: 0.5em;
}
}
}
/* where ::shadow only goes into the direct shadow child, /deep/ goes into all ancestors */
video /deep/ input[type=button]:first-child {
background: red;
-webkit-appearance: none;
}
JavaScript
var root = document.querySelector('div.custom-new').createShadowRoot();
root.innerHTML = '<div><h3>Shadow</h3><p>This is in a shadow DOM</p></div>';
var root2 = document.querySelector('x-foo').createShadowRoot();
root2.innerHTML = '<div><h3>Foo</h3><p>This is in a shadow DOM in an x-foo element</p></div>';