[docs] No search results for `How can we apply CSS styles to nested elements inside the slot`

未关闭
#1,384 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
30/100
Issue 类型
文档
描述清晰度
需要澄清
活跃度
停滞
技术栈
css
领域
documentation

调研方向

从链接的 Shadow DOM 文档开始,检查所报告的 slot 示例和列出的两种解决方法。确定文档是否需要一个专门介绍如何设置嵌套 assigned content 样式的示例;完成的标准是将相关指导和示例添加到 lit.dev,并解答所报告的问题。

由索引模型根据 Issue 内容生成。

描述

Hi Team,

Could you please help us in applying the CSS to nested elements inside the slot.

Eg:

Render me in a slot

How can we apply the css to span with class redText inside a P tag which is a slot. It would be helpful if you can share some examples. I have already gone through your workarounds, but couldn't execute it.

Workaround 1 - Use Javascript To Style

(1) Access the slotted elements from javascript by using @queryAssignedElements (See https://lit.dev/docs/components/shadow-dom/#query-assigned-nodes)

(2) For each slotted element, parse its dom tree and style the child nodes using javascript (e.g. childelement.style.backgroundColor = '#ff0';)

Workaround 2 - Copy Slotted HTML to Another Div

(1) Access the slotted elements from javascript by using @queryAssignedElements (See https://lit.dev/docs/components/shadow-dom/#query-assigned-nodes)

(2) For every slotted element under consideration, copy-paste its outerHTML to another empty div, placed next to it.

(3) Since these initially empty divs are not from the slots, you can setup static css rules for them.

(4) Empty the slots after the copy pasting into the adjacent divs is complete.

Regards
Rajesh

主要语言
TypeScript
星标
140
派生
229
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lit/lit.dev 的其他 Issue

查看 lit/lit.dev 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。