CC0
<core-scaffold>
<core-header-panel>
<core-toolbar>Chat Room</core-toolbar>
</core-header-panel>
<template repeat="{{m in messages}}">
<x-chat-list uuid="{{m.uuid}}" text="{{m.text}}"></x-chat-list>
</template>
<paper-input on-keyup="{{checkKey}}"></paper-input>
<paper-fab icon="send"></paper-fab>
</core-scaffold>
Shadow DOM enable markup to:
<audio src="media/meow.mp3" controls></audio>
<input type="date">
SoundBible.comb
<audio src="media/meow.mp3" controls></audio>
<input type="date">
SoundBible.comb
<x-chat-list
color="moss" avatar="korat" username="Moss-Korat"
text="happy moew year to you all"
timestamp="a minutes ago"></x-chat-list>
DOM & Shadow DOM
<div id="parent"></div>
var parent = document.querySelector('#parent');
var child = document.createElement('div');
parent.appendChild(child);
<div id="host"></div>
var host = document.querySelector('#host');
var shadowroot = host.createShadowRoot();
// To append a child node to the shadow root
var child = document.createElement('div');
shadowroot.appendChild(child);
:host
and :host()
pseudo-class:host-context()
pseudo-class::content
pseudo-element::shadow
pseudo-element>>>
shadow-piercing descendant combinatorCSS Scoping Module Level 1 • http://dev.w3.org/csswg/css-scoping/
<element name="x-chat-list">
<style>
:host {
border-bottom: 1px solid #eee;
min-height: 72px;
}
</style>
<div class="username"></div>
<div class="text"></div>
<template>...</template>
</element>
<element name="x-chat-list" class="fancy">
<style>
:host(.fancy) {
border-bottom: 3px dashed LemonChiffon;
}
:host(:hover) {
color: DarkSlateBlue;
}
</style>
...
</element>
:host-context(.fancypants) {
background-color: LavenderBlush;
}
<div class="fancypants">
<x-chat-list></x-chat-list>
</div>
<element name="x-chat-list">
<style>
::content span {
font-weight: 400;
}
</style>
<div class="username"><span>User: </span></div>
<div class="text"></div>
<template>...</template>
</element>
x-chat-list::shadow > div {
min-height: 100px;
}
<x-chat-list>
#shadow-root
<div>...</div> <-- this is selected
</x-chat-list>
* deprecated in Chrome recently: https://www.chromestatus.com/features/6750456638341120
Shadow-piercing descendant combinator
x-chat-list >>> div { ... }
<x-chat-list>
#shadow-root
<div> <-- all divs are selected incl. nested divs
<div>
<div></div>
</div>
</div>
</x-chat-list>
audio.fancy >>> input[type=range] {
background-color: CornflowerBlue;
}
Actual DOM:
Screenshot:* Both /deep/ and the combinator are deprecated in Chrome: https://www.chromestatus.com/features/6750456638341120
https://flic.kr/p/8jP4NJ by Ryusuke b