I have
main.js and index.html below
class CustomTagA extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({mode: 'open'});
const wrapper = document.createElement('h1');
wrapper.setAttribute('class', 'wrapper');
wrapper.textContent = 'Custom Tag A';
shadow.appendChild(wrapper);
}
}
class CustomTagB extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({mode: 'open'});
const wrapper = document.createElement('a');
wrapper.setAttribute('class', 'wrapper');
wrapper.textContent = 'Custom Tag B';
shadow.appendChild(wrapper);
}
}
customElements.define('cutomtag-a', CustomTagA);
customElements.define('cutomtag-b', CustomTagB);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<cutomtag-a></cutomtag-a>
<cutomtag-b></cutomtag-b>
<script src="./main.js"></script>
</body>
</html>
When my code running on browser i have inpect html and discover them. I have few questions about Shadow Element
- Where default css of Shadow Host Element?
- Why cutomtag-a beak line while it display Inline? Is it because i use h1 tag?What is their working principle? Where can I find documents?