How do you style a web component to suit your needs? In this episode, Lit Software Engineer Andrew Jakubowicz explains how the Shadow DOM works, illustrates the benefits of encapsulated CSS, and shows how you can use CSS inheritance, custom properties and shadow parts to build web components with flexible, public styling APIs.
The concepts and tools discussed here apply regardless of whether you’re using Lit to build your web components.
Links:
MDN Using CSS Custom Properties → goo.gle/3RzOl97
MDN part attribute →goo.gle/3CgJJA1
MDN ::part() → goo.gle/3Sk2ckN
MDN exportparts → goo.gle/3Rpv9dU
Playground Elements →goo.gle/3fpTFOK
Build an animated carousel tutorial → goo.gle/3rffdjH
Lit documentation site → goo.gle/Lit-devsite
Simple Carousel Github → goo.gle/3kmGEor
Chapters:
0:00 - Intro
1:40 - How styles behave by default with Lit
Code → goo.gle/3SkFUzx
4:45 - Inherited CSS properties
5:30 - Custom Properties
7:35 - Demo 1: Use Custom Properties to customize a Lit element
Code → goo.gle/3UKnauK
8:25 - Shadow Parts
11:20 - Demo 2: Use Shadow Parts to customize a Lit element
Code → goo.gle/3SE3irp
12:25 - Demo 3: Use Shadow Parts to style an automatic carousel
Code → goo.gle/3fvAD9W
13:12 - Showcase public styling interface of playground-element
13:50 - Recap
Have any lingering questions? Tweet at us with the hashtag AskLitDev or join the Lit community Discord!
Join the community → goo.gle/Lit-Community
Github Discussions → goo.gle/Lit-GitHub
Twitter → goo.gle/Lit-Twitter
Discord → goo.gle/Lit-Discord
Watch more Build it with Lit → goo.gle/BuilditwithLit
Subscribe to never miss a video on Lit → goo.gle/Lit
#Lit #WebComponents #WebDevelopment
6 авг 2024