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

Đang mở
#1,384 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
30/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
css
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với tài liệu Shadow DOM được liên kết và xem xét ví dụ slot được báo cáo cùng hai cách giải quyết được liệt kê. Xác định xem tài liệu có cần một ví dụ tập trung về việc tạo kiểu cho nội dung được gán lồng nhau hay không; công việc được xem là hoàn tất khi hướng dẫn và ví dụ liên quan được thêm vào lit.dev và giải đáp câu hỏi đã nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
140
Fork
229
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lit/lit.dev

Tất cả issue của lit/lit.dev

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.