<slot>: Web Component 的 Slot 元素
<slot>
HTML 元素 — Web Components 技术套件的一部分 — 是 Web Component 内部的一个占位符,您可以用自己的标记填充它,从而创建独立的 DOM 树并将它们组合在一起呈现。
属性
此元素包含全局属性。
示例
html
<template id="element-details-template">
<style>
details {
font-family: "Open Sans Light", "Helvetica", "Arial", sans-serif;
}
.name {
font-weight: bold;
color: #217ac0;
font-size: 120%;
}
h4 {
margin: 10px 0 -8px 0;
background: #217ac0;
color: white;
padding: 2px 6px;
border: 1px solid #cee9f9;
border-radius: 4px;
}
.attributes {
margin-left: 22px;
font-size: 90%;
}
.attributes p {
margin-left: 16px;
font-style: italic;
}
</style>
<details>
<summary>
<code class="name">
<<slot name="element-name">NEED NAME</slot>>
</code>
<span class="desc"><slot name="description">NEED DESCRIPTION</slot></span>
</summary>
<div class="attributes">
<h4>Attributes</h4>
<slot name="attributes"><p>None</p></slot>
</div>
</details>
<hr />
</template>
注意:您可以在 element-details 中看到这个完整的示例(也可以 在线运行)。此外,您可以在 使用模板和 Slot 中找到相关的解释。
技术摘要
内容类别 | 流内容,短语内容 |
---|---|
允许内容 | 透明 |
事件 | slotchange |
标签省略 | 无,起始标签和结束标签都必须存在。 |
允许父级 | 接受 短语内容 的任何元素 |
隐式 ARIA 角色 | 没有对应的角色 |
允许的 ARIA 角色 | 不允许 role |
DOM 接口 | HTMLSlotElement |
规范
规范 |
---|
HTML # the-slot-element |
DOM # shadow-tree-slots |
浏览器兼容性
加载中…
另见
- HTML
<template>
元素 - HTML
slot
属性 - CSS
::slotted
伪元素 - CSS :has-slotted 伪类
- CSS 作用域模块