Tether to multple elements
Key Takeaways
The video demonstrates how to use CSS anchor positioning to connect one element to another with a visual indicator, specifically using the ':after' pseudo-element and anchor names.
Full Transcript
If you've ever needed to connect one element to another one with a little visual indicator like we have here with these threads, it's actually really easy to do with a bit of modern CSS. You can see here I have my comment. Nested inside the comment is the replies UL, and each one of these guys here is the div with a reply. And now jumping on over to my CSS, I've turned off the threads to show us how we were doing this. Uh, but each one of those replies I am giving a after pseudo element, but basically have a border on the left side and on the bottom, which will create the line. So, how do we do that? Well, that means my comment is going to need to be an anchor. So, we're going to say dot comment has an anchor name of comment. Uh, and then I'm also going to come in and say that all of my replies are the same. So, reply uh double hyphen reply. So, here I have a position absolute already on my pseudo element. And what we're going to say is the top of the pseudo element is going to go to the initial comment all the way to the top. So, we're going to say anchor top of that comment. There, let's just give this really fast a width of 10 pixels and a height of 10 pixels and a background of red so we can actually see it. And if I turn off this comment uh right there, we can see the red things are actually here, here, and over here instead. Uh, maybe I'll make that yellow so it stands out even more. The top is anchored to the top of the comment. I made a mistake there. That should be the bottom of my comment, and it's moved down over to the bottom. The next thing I want to do is go and grab my left side. Should be my anchor left my comment. Then we can come in on my bottom. I'm going to say anchor to the center of each reply. And it doesn't look like it's working, but that's because I gave it a height. If I take that height off now, we can see it's stretching from the top here all the way down to over here. And for now, I'm going to turn off this background and just make the border a little bit thicker so we can see it a little bit better. One last one that we're going to want to do on here is to come in with the right side, and the right side of this should be anchored to the left side of that reply. So, we can say anchor we want it to be the left of my reply. And here I had a width. We can take that width off now, and it's connecting from here and going all the way and connecting to that side there. On that left, we can add a calc, and with that calc, we can just wrap this entire thing in and say that we want to do plus point plus I think it's one rem maybe to get it closer to the middle there. And if I bring this back down to being one pixel, it's going to look a little bit better. But you're probably noticing a little bit of a problem. We're only connecting to the bottom one, and we're not connecting to these two over here. And that's because all of my replies currently have the same anchor name, and so this after is going, "Well, where's my anchor name?" CSS last thing wins, they all go down to the bottom. I can come over here and also give this an anchor scope and give it the exact same name. And so as long as something is a descendant of the reply, which an after is as a pseudo element, it's a descendant of the reply, that anchor name that it's looking for will be scoped to that parent. I can clearly see now that these are individually linked.
Original Description
Anchor positioning is one of my favorite new CSS features.
#css
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Kevin Powell · Kevin Powell · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to create an awesome navigation bar with HTML & CSS
Kevin Powell
Improve your CSS by Keepin' it DRY
Kevin Powell
HTML & CSS for Beginners Part 6: Images
Kevin Powell
HTML & CSS for Beginners Part 7: File Structure
Kevin Powell
HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
Kevin Powell
HTML & CSS for Beginners Part 5: Links
Kevin Powell
HTML & CSS for Beginners Part 3: Paragraphs and Headings
Kevin Powell
HTML and CSS for Beginners Part 1: Introduction to HTML
Kevin Powell
HTML and CSS for Beginners Part 2: Building your first web page!
Kevin Powell
HTML & CSS for Beginner Part 8: Introduction to CSS
Kevin Powell
HTML & CSS for Beginners Part 9: External CSS
Kevin Powell
HTML & CSS for Beginners Part 10: Divs & Spans
Kevin Powell
HTML & CSS for Beginners Part 11: Classes & IDs
Kevin Powell
HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
Kevin Powell
HTML & CSS for Beginners Part 13: Background Images
Kevin Powell
HTML & CSS for Beginners Part 14: Style Text with CSS
Kevin Powell
HTML & CSS for Beginners Part 15: How to style links
Kevin Powell
HTML & CSS for Beginners Part 16: CSS selectors and Specificity
Kevin Powell
HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
Kevin Powell
HTML & CSS for Beginners Part 18: How Floats and Clears work
Kevin Powell
HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
Kevin Powell
HTML & CSS for Beginners Part 20: How to center a div
Kevin Powell
HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
Kevin Powell
HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
Kevin Powell
How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
Kevin Powell
How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
Kevin Powell
How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
Kevin Powell
How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
Kevin Powell
How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
Kevin Powell
Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Kevin Powell
End of the year upate and what's coming to my channel to start the new year
Kevin Powell
Create a CSS only Mega Dropdown Menu
Kevin Powell
CSS Tutorial: Outline and Outline Offset
Kevin Powell
CSS Blending Modes
Kevin Powell
Parallax effect | 2 different ways to add it with jQuery
Kevin Powell
CSS Units: vh, vw, vmin, vmax #css #responsive #design
Kevin Powell
How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
Kevin Powell
100 Subscribers speed coding bonus video
Kevin Powell
How to Create a Website - Complete workflow | Part 02: The Markup #HTML
Kevin Powell
How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
Kevin Powell
How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
Kevin Powell
How to Create a Website - Complete workflow | Part 05: Typography & Buttons
Kevin Powell
How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
Kevin Powell
How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
Kevin Powell
Redesigning & Coding My Website #CreateICG
Kevin Powell
How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
Kevin Powell
How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
Kevin Powell
How to Create a Website - Complete workflow | Part 09: The CTA and Footer
Kevin Powell
How to Create a Website - Complete workflow | Part 10: Making it responsive
Kevin Powell
How to Create a Website - Complete workflow | Part 11: Making it responsive con't
Kevin Powell
How to Create a Website - Complete workflow | Part 12: Putting the site online
Kevin Powell
Create a Custom Grid System with CSS Calc() and Sass
Kevin Powell
CSS em and rem explained #CSS #responsive
Kevin Powell
Should you use Bootstrap?
Kevin Powell
How to add Smooth Scrolling to your one page website with jQuery
Kevin Powell
Let's learn Bootstrap 4
Kevin Powell
How I approach designing a website - my thought process
Kevin Powell
Build a website with Bootstrap 4 - Part 1: The setup
Kevin Powell
Build a website with Bootstrap 4 - Introduction
Kevin Powell
Build a website with Bootstrap 4 - Part 2: Customizing Variables
Kevin Powell
Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI