CSS Anchor Is The Best New CSS Feature Since Flexbox

Поделиться
HTML-код
  • Опубликовано: 4 июн 2024
  • I cannot believe this is a feature coming to HTML/CSS. Anchoring elements used to be only something you could do with hundreds of lines of complex JavaScript code, but now it can be done with a single line of CSS. I am incredibly excited for this feature to be production ready as it has the potential to massively change web development.
    📚 Materials/References:
    Chrome Flags: chrome://flags/#enable-experimental-web-platform-features
    Anchor Chrome Blog Article: developer.chrome.com/blog/tet...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:26 - Demo
    01:20 - Popover API
    02:50 - Anchor Basics
    07:40 - Advanced Anchor Features
    11:45 - Advanced Example
    #CSSAnchor #WDS #CSS

Комментарии • 343

  • @ozzyogkush
    @ozzyogkush 9 месяцев назад +425

    We have like 3 separate implementations of context menus, popovers, etc at my current workplace. Being able to replace some of that complexity with this would be a big win and a nice tech debt reduction!

    • @evergreen-
      @evergreen- 9 месяцев назад +223

      You’ll end up having 4 separate implementations

    • @shivanand0297
      @shivanand0297 9 месяцев назад +17

      ​@@evergreen-😂

    • @BboyKeny
      @BboyKeny 9 месяцев назад +5

      I'm also extremely happy with this feature. So many different implementations...

    • @ongke3655
      @ongke3655 9 месяцев назад +18

      But wait until browsers support

    • @ozzyogkush
      @ozzyogkush 9 месяцев назад +10

      ​@@evergreen- it's the truth tho...

  • @DamirSecki
    @DamirSecki 9 месяцев назад +138

    I share your excitement.... This looks great and cannot believe that this hasn't been done like 5-10 years ago. We all know that menus and popovers are user everywhere... and is really mind boggling that it is taking so long to get native support.... I am so glad we have auto updating browsers now that when new features come out, in most cases, they are available to the user straight away

    • @IIARROWS
      @IIARROWS 7 месяцев назад +4

      LOL, no... you have to look for at least 2 years old features, 3 to be sure. Depending on your target user you could live with less.
      Browser don't update constantly as you think, especially on older devices, or if you want your site to be usable from offices.

    • @rproctor83
      @rproctor83 7 месяцев назад +3

      @@IIARROWS Having worked with various Sheriff's offices I can confirm that they still use old IE.

    • @eobardthawne6903
      @eobardthawne6903 3 месяца назад

      ​@@IIARROWS Yupp true, even the ones using relatively new device won't keep auto update on

  • @GeneraluStelaru
    @GeneraluStelaru 9 месяцев назад +51

    Finally, baby CSS is growing up. Last year I worked on a project where I had to learn QML. Neddless to say, I didn't want to deal with web frontend anymore.

    • @philippedcote
      @philippedcote 9 месяцев назад +1

      You used QML with Qt or another framework?

    • @pinkorcyanbutlong5651
      @pinkorcyanbutlong5651 9 месяцев назад +3

      @@philippedcote I'm quite sure qml only works with qt

    • @GeneraluStelaru
      @GeneraluStelaru 9 месяцев назад

      @@pinkorcyanbutlong5651We had Qt licences but QML works on top of C++. Qt is essentially just an IDE.

    • @llothar68
      @llothar68 3 месяца назад

      Nothing beats native GUI toolkits unless you are doing design shit, but for apps its the best

  • @EricRohlfs
    @EricRohlfs 9 месяцев назад +7

    This is excellent. Glad we finally figured out the three main actions are show, hide, and toggle and found a way to associate with click with zero JavaScript. Best video I've seen all year!

  • @EvertJunior
    @EvertJunior 9 месяцев назад +69

    This is long overdue. It's insane we have so many UI libraries with different implementations of select menus and popovers just so we can build a decent UI/UX. This feature along view transitions will enable awesome looking and performant web apps.

    • @PeterMumford
      @PeterMumford 9 месяцев назад +2

      yes, this. I want to add CSS transitions.

    • @profesor08
      @profesor08 7 месяцев назад +2

      And no one works well xDDDD

  • @dennisb_official
    @dennisb_official 9 месяцев назад +11

    Always a pleasure getting up to date with the latest web tech from you mate. Your way of teaching really resonates well with me.
    Thank you for being one of the best YT channels out there.

  • @Nakabozu
    @Nakabozu 9 месяцев назад +17

    This is AMAZING! Really hoping this is stable soon because I'll use it absolutely everywhere.

  • @ukaszzbrozek6470
    @ukaszzbrozek6470 9 месяцев назад +7

    Thanks for keeping us in loop with the newest features!

  • @NoName-1337
    @NoName-1337 9 месяцев назад +16

    This feature is amazing. Can't wait to use it in production.

  • @foxxo-dev
    @foxxo-dev 9 месяцев назад +8

    Thanks for all of the great content that you make, keep up the great work!

  • @jamesmoynihan948
    @jamesmoynihan948 7 месяцев назад +10

    This is a really nice feature, but what makes anchor really useful is when you have more complex positioning and stacking contexts. I particularly found it useful for tooltips within a element which is the first element to use the popover API under the hood and lives in the special "top layer" above all other stacking contexts (kinda like "z-index: infinity").

  • @lukas.webdev
    @lukas.webdev 9 месяцев назад +2

    Great Video! Thanks for keeping us up to date, Kyle! 😉🔥

  • @Ferno2k
    @Ferno2k 9 месяцев назад +5

    Omg I am a newbie working on a full stack project and this is exactly what I wanted to create in my frontend. I was earlier using the dailog element as remediee to create drop down option

  • @jitesh031
    @jitesh031 9 месяцев назад +3

    This is really a good feature to minimize the js code where in past we have to check, "related target" and then make it display flex or none. Here we just have to assign an id. Amazing !!!

  • @monarchgam3r
    @monarchgam3r 9 месяцев назад +10

    These new APIs coming native to browsers is huge

  • @keitsee
    @keitsee 7 месяцев назад +1

    Thank you so much for this. Words cannot explain how much this is so good. Really, really good. Having to display:flex the element then z-index it to make sure its on top of all elements then making sure the document click outside of the element closes the element all in js. Popover just solves everything.

  • @netssrmrz
    @netssrmrz 9 месяцев назад +3

    Super good video. Learned something new today. Nice to see genuinely useful info rather than another React/Next/Typescript video.

  • @kiravolvo
    @kiravolvo 9 месяцев назад +1

    kyle thank you very much. your videos are so clear and easy to follow. rock on!

  • @ararthepro3972
    @ararthepro3972 8 месяцев назад +4

    Waited for this feature a lot of time, my hope was it will be like "binding" properties values so you could copy all properties and values from other elements (like height, width, etc) not only inset, but that's a start (though I assume anchora will be stable in at least 3 years, if it will)

  • @damar1967
    @damar1967 9 месяцев назад +1

    So excited! Its like with details and summary but the position could be anywhere

  • @Nutch.
    @Nutch. 9 месяцев назад +1

    This is game changing. I wonder if support will be added to detect which @try fallback is currently active. An example of why this would be useful is for rotating a menu chevron to the correct direction that the menu will appear from when opened.

  • @KD-tp6er
    @KD-tp6er 9 месяцев назад +9

    I'm grateful I'm building websites with all these new tools, I've heard horror stories of making websites using tables back in the day.

    • @GamerGuyplays
      @GamerGuyplays 9 месяцев назад +6

      Making websites wasn't really a pain, but getting things exactly as you wanted, that was the really anoying part

    • @stefanlindbohm
      @stefanlindbohm 8 месяцев назад +2

      Using tables wasn’t the bad part (it was basically a simplistic grid). The real horror started when we were all moving away from them and every relevant browser implemented CSS layout in different ways, with the dominant browser (IE6) being both hugely incompliant with any documented standards as well as going without updates for almost a decade.

  • @gouravchouhan1790
    @gouravchouhan1790 4 месяца назад +1

    I was about to make something like this and no way I found your short and from short I found your video this is amazing

  • @ascodes3461
    @ascodes3461 9 месяцев назад +1

    Awesome man, Thanks a lot for this information😍🥰

  • @bartek4210
    @bartek4210 9 месяцев назад +1

    Amazing! thanks for showing it!

  • @Nobi-on-Guitar
    @Nobi-on-Guitar 9 месяцев назад +1

    Very informative ❤ Thank you so much 😍

  • @GaneshKumarNow
    @GaneshKumarNow 9 месяцев назад +1

    Wow. This feature is amazing 👏🏻 thanks for sharing with us 👍🏻

  • @mzosam
    @mzosam 17 дней назад

    I just put thumbs up to your videos before I even watch them🔥always have been and will always be the best teacher

  • @patricknelson
    @patricknelson 8 месяцев назад +2

    _One major_ benefit to popover: Accessibility! Semantic markup is perfect for overall a11y and screen readers.

  • @YourUncleisGaySimba
    @YourUncleisGaySimba 4 месяца назад +2

    I just spent like 3 hours figuring out how to implement this in react (with some async data) and ended up using the classic css focus to show a child of a certain element.
    Appreciate the work tho!

  • @lewsdiod
    @lewsdiod 4 месяца назад +1

    Very cool, glad to see it! Thanks fro sharing!

  • @nicksullivan23
    @nicksullivan23 8 месяцев назад +1

    Wicked loving this feature and great tutorial 🎉

  • @FrameMuse
    @FrameMuse 9 месяцев назад +2

    Actually, for some implementations we could just use `@position-fallback` along with `transform` and some other positioning.

  • @Pikachu-oo5ro
    @Pikachu-oo5ro 9 месяцев назад +2

    I can see the honesty from your videos man, you never sell us anything! You're dedicated to our learning! I'm glad you made it!

  • @yassine_klilich
    @yassine_klilich 5 месяцев назад +1

    incredible new features, so excited when they will be available across major browsers sooner

  • @user-db1ue8om7v
    @user-db1ue8om7v 9 месяцев назад +1

    Super cool stuff, love where the web is going!

  • @tiendatnguyen6239
    @tiendatnguyen6239 9 месяцев назад

    This is amazing. Thank you very much.

  • @thekaasim
    @thekaasim 9 месяцев назад

    Thanks so much.. All of these are new to me ❤🎉

  • @juneroyd.quinimon495
    @juneroyd.quinimon495 8 месяцев назад +1

    Thanks for the tutorial!

  • @aleksandarv.1459
    @aleksandarv.1459 4 месяца назад +1

    Keep up the good work, Kyle!

  • @BenRogersWPG
    @BenRogersWPG 9 месяцев назад

    Very cool. Thanks for this!

  • @TesterAnimal1
    @TesterAnimal1 7 месяцев назад

    Had this for years in my app.
    Simpler API for the devs to use. And handles more cases.
    Fallback when scrolling or in anyway dynamically repositioning inside a constraining element (such as the viewport) will reduce the constrained size up to a breakpoint I’d configured too do so before falling back to other orientations.
    And it can fall back either by flipping sides first, then trying the other two. Or just rotating from the side where constraining failed.

  • @musicforlife4571
    @musicforlife4571 7 месяцев назад +1

    Thanks for sharing this!

  • @LuniFoxo
    @LuniFoxo 9 месяцев назад +9

    Thank you for the advice, Kiss Splat!

  • @dasten123
    @dasten123 9 месяцев назад +1

    Interesting. All popover libraries I know have some kind of flaw. I'm excited to see how well this will work with layout-shifts and scrolling.

  • @stefanlindbohm
    @stefanlindbohm 8 месяцев назад +6

    Awesome & easily understood video with good examples! The popover feature of HTML is news to me and will be a huuuge improvement!
    Just wanted to mention that anchoring is easily implemented with good old position absolute + relative. Just create a container with position: relative (the anchor) then put the popover inside with position: absolute. Positioning works mostly (exactly) the same as this anchoring CSS proposal, and because all contents of the container are taken out of flow, the container will have no size and can be put anywhere without side effects.
    In general, I’d be very cautios with using or promoting proposals that aren’t yet in the standards. For one, they might change before becoming a standard, but worse it creates browser dependencies and results in fragmentation of the web much in the same way we had back with Internet Explorer 6. Trust me, we don’t want to have that situation again.

  • @theisoj
    @theisoj 9 месяцев назад +1

    Thanks Kyle as always! 👍

  • @mr.w7803
    @mr.w7803 4 месяца назад +1

    Wow, this is awesome.
    I stepped away from UI dev a couple years ago due to some intense frustration (partly never ending updates to libraries, languages, etc… mostly i liked design better 😅). Glad to see things are getting easier though!

  • @D9ID9I
    @D9ID9I 3 месяца назад

    That's good. Infinite horizontal and vertical scrolls would be nice to add too. And "virtual" scroll with elements of different height also.

  • @PsychoDude
    @PsychoDude 9 месяцев назад

    I need this in my project and I am doing so much work. wish this was more supported

  • @Allformyequine
    @Allformyequine 9 месяцев назад

    AwesomeSauce!!!! Luv it! Thank you!

  • @tobiasbrenner7176
    @tobiasbrenner7176 9 месяцев назад

    Awesome video. Thank you

  • @SandWire
    @SandWire 8 месяцев назад

    I done this only using CSS too, but I just used hover. It works the same, but you need to hover not just clicking on the (i). On Android hover works like clicking :)

  • @LarsRyeJeppesen
    @LarsRyeJeppesen 9 месяцев назад +1

    A video without React? finally I can watch and enjoy :)

  • @anyalir
    @anyalir 9 месяцев назад +10

    I didn't know before Chrizs Pradt is doing such great content!!

  • @akramilyas6030
    @akramilyas6030 9 месяцев назад

    waaaw i cant think of how much u can be creative with it

  • @philipphock7591
    @philipphock7591 9 месяцев назад +4

    what's the difference between anchor and position: relative/absolute? Would be nice to elaborate on that!

  • @shayanzamani9907
    @shayanzamani9907 9 месяцев назад

    It's awesome! just a quick question: How's the a11y handled for this thing?

  • @sequoiakanies2202
    @sequoiakanies2202 4 месяца назад

    Great video, maybe should have started with the with the fact that it’s not supported quite yet but cool to know about anyway

  • @aro9648
    @aro9648 9 месяцев назад

    btw you can easily close browser card by clicking mouse wheel on it instead X sign ;)

  • @niner8275
    @niner8275 8 месяцев назад +1

    That's quite a revolution, like :has() or grid.

  • @tinongnjong1305
    @tinongnjong1305 9 месяцев назад

    Really great, appreciate it 👋🏾

  • @QwDragon
    @QwDragon 9 месяцев назад

    Great features!
    But do I understand right that anchor-name should be unique on the page? So if I have several similar blocks I can't scope ancor iside of a block, can I?

  • @soulehshaikh8799
    @soulehshaikh8799 3 месяца назад

    Just love the tutorials ❣

  • @neoqueto
    @neoqueto 7 месяцев назад

    I think it was possible to recreate the popover thing with a janky checkbox with :checked and :active property selectors but that anchor stuff is pretty sweet

  • @Yoremh
    @Yoremh 4 месяца назад

    hi Kyle! thanks for this tutorial :) always a pleasure to follow your videos! I've a problem with anchor tag : when i put this attr on my popover element i can't open the modal on click.. I use Chrome (latest version)

  • @MKTheDev
    @MKTheDev 9 месяцев назад +1

    Great tip!

  • @ErnaSolbergXXX
    @ErnaSolbergXXX 8 месяцев назад

    This is the most exciting news when it comes to web development for a long time.

  • @prashlovessamosa
    @prashlovessamosa 9 месяцев назад +1

    My friend and me together 😁 bought your react course
    Complete 4 parts of beginner one
    Totally worth my money.

    • @lukas.webdev
      @lukas.webdev 9 месяцев назад

      Awesome, keep it up! 😉

    • @WebDevSimplified
      @WebDevSimplified  9 месяцев назад

      I am really glad you are enjoying the course!

  • @ryanschaefer4847
    @ryanschaefer4847 9 месяцев назад

    This is incredible!

  • @patrickgray1758
    @patrickgray1758 Месяц назад +1

    It's coming this May!!

  • @poesiapartida
    @poesiapartida 9 месяцев назад

    This is amazing! Really! So long, long javascript code to position stuff!

  • @marcosantonioreyesmedina2364
    @marcosantonioreyesmedina2364 9 месяцев назад

    OMG is amazing, recently i was a develop a similar contextual

  • @smilerbob
    @smilerbob 3 месяца назад

    Nice features but not supported everywhere
    Now all of my webpages with simple , , and tags have never gone wrong with browser updates, OS upgrades or using in different platforms 👍😁

  • @ghostaccountlmao
    @ghostaccountlmao 9 месяцев назад +1

    This seems very, very useful

  • @Kay_Drechsler
    @Kay_Drechsler 9 месяцев назад +1

    This is awesome and makes me really happy that it’s nearly finally there. One thought that came up when you were showing the popover menu at the end. Is it still considered to be good markup / accessible markup when the child popovers are not nested inside the parent popover’s list but instead life as siblings right next to it? I wonder how a user of a screenreader could understand this.

    • @xXYourShadowDaniXx
      @xXYourShadowDaniXx 9 месяцев назад

      I think you would just aria-hidden toggle based on button click/hover, so by default its hidden, and on button click or hover, it unhides for the reader, then on click/mouseout it aria hides again.

    • @robertlinder8464
      @robertlinder8464 9 месяцев назад

      The a11y aspect will most certainly be handled by the UA, good stuff!

  • @bojack4800
    @bojack4800 9 месяцев назад

    thx for u share!

  • @alexandraweather4156
    @alexandraweather4156 4 месяца назад

    Omg
    Watched this video just now, five months after its release, and both of these features have more than 70 percent of support!

    • @twanadler9
      @twanadler9 4 месяца назад

      Its not working on my vscode😂

    • @alexandraweather4156
      @alexandraweather4156 4 месяца назад

      @@twanadler9 didn’t even try yet - I wait for 90% of support

  • @jensensphotography4570
    @jensensphotography4570 2 месяца назад

    im just curious but lets just say we had an Tag. and i wanted to move it to a specific area. what is better to use? Translate, positions, or margin? iv only just seen translate now on this video and looked it up. and seems the best way to just move an element. and with translate when you move the element from its position. does 10px 20px move its current position from where it first was?

  • @TheOnceAndFutureDoug
    @TheOnceAndFutureDoug 7 месяцев назад +1

    I hope the idea of naming anchors can be nested. Otherwise I have concerns about name conflicts. Though I suppose you could set the anchor ID via an inline style attribute to set a CSS custom property... It's kinda ugly but it would work. Hopefully they consider that and make it more elegant.

    • @jamesmoynihan948
      @jamesmoynihan948 7 месяцев назад

      I think the next step would be appending guids to avoid that naming collision.

  • @knaz7468
    @knaz7468 9 месяцев назад +3

    Hey Kyle. I took some of your classes a while back and enjoyed them. Sadly I didn't "use" my knowledge right away and lost a lot of it, but the basics are still there. Fast forward to now, and I really want to setup a web site with an active server so I can do my own DB admin, javascript, python, etc on the server and then make a slick looking html/css/javascript enabled client side. However, I'm struggling with hosting options. They are seem very confusing and expensive. I searched your video library but didn't see any info on this. Is there a preferred method you have for setting up a server? Do you prefer shared/vps/cloud/etc? Thanks! I'll try your discord as well.

    • @reed6514
      @reed6514 8 месяцев назад

      I've used shared for years, and have been happy. I work in php, but i imagine most shared servers support python. I use dreamhost & in some ways i like them, others i don't. Godaddy, bluehost, Hostgator i think are all fine options. Of those three I preferred bluehost, but it's been 5+ years.

    • @reed6514
      @reed6514 8 месяцев назад

      I have used vps before, when i wanted it to be a little faster. My shared host sites on dreamhost have about a 200ms response time on my internet, and vps I've used was like 50ms. The 50ms is nice, but it's not necessary.

    • @USPSLaura
      @USPSLaura 5 месяцев назад

      I can volunteer to work with you 😊

  • @CCD-yp6hh
    @CCD-yp6hh 8 месяцев назад

    Wow, that is really cool. I found your video because I was looking up how to keep my parallax background images in place when I resize my screen. The images are in a grid and all the parallax demo video only have one background image: I have three images. Anyway, your video gave me some ideas to try out and see if I can make my background images on the parallax grid responsive. So, thanks a bunch!! P.S. if you or anyone knows the solution to my parallax issue then please let me know. Thanks again.

  • @Theguy831blah
    @Theguy831blah 9 месяцев назад

    Best web dev channel

  • @habsi70
    @habsi70 6 месяцев назад

    Wonderful, thank you! Now the ususal wait for wide browser support for the new features :(

  • @chinmayghule8272
    @chinmayghule8272 9 месяцев назад +1

    I used to get excited over these things when I had just started learning web development. I'm still a noob. But I think that most people are just going to use their favority UI libraries in their work or projects regardless of what latest features may come.

    • @AanchalMittal-ku4lu
      @AanchalMittal-ku4lu 9 месяцев назад

      ruclips.net/user/shortsNOYmNsgcKhw?si=T-8MQnprAsVunmRM

  • @raph151515
    @raph151515 9 месяцев назад +4

    in 2009 I developed in AS3 a declarative (xml) ui engine and it had what I call anchor (relative position between elements) and collisions which handle the screen limits and the collisions between elements and this system will switch to an alternative position and potentially re-evaluate another collision detection, it was perfect to build menu bars, context menu or satellite elements that are relative to responsive elements. The anchor system supported values (left, center...) for the anchor element and the current element independently and supported numerical values (0 is left, 1 is right, any float value was supported, very nice to put something at 50% for instance

    • @jingle1161
      @jingle1161 9 месяцев назад

      So..?

    • @raph151515
      @raph151515 9 месяцев назад

      it means that they take their sweet time to come up with needed solutions
      @@jingle1161

    • @turolretar
      @turolretar 9 месяцев назад +1

      @@jingle1161this is youtube, not stack overflow, if that’s what you mean.

    • @olezhonnv3215
      @olezhonnv3215 8 месяцев назад +1

      I coded in AS3 too) But I coded in imperative style.

    • @USPSLaura
      @USPSLaura 5 месяцев назад

      Am struggling on getting job as a frontend developer, any cues to land one

  • @geraldopcf
    @geraldopcf 9 месяцев назад

    gmapdev: popover and Anchor Features are awesome.

  • @blenderpanzi
    @blenderpanzi 5 месяцев назад

    Will be cool once we can use that! (Firefox is missing popover and Safari is missing anchor. And caniuse doesn't even know position-fallback.)

  • @pinkorcyanbutlong5651
    @pinkorcyanbutlong5651 9 месяцев назад

    finally, css gets one of the most basic essential features of any ui design tool!
    being both sarcastic and excited, hope this lands on firefox soon

  • @PaweBystrzan
    @PaweBystrzan 8 месяцев назад

    for now using just target is better than popover, but maybe it'll be nice to have it in the future not only for the popover / tooltip

  • @allandiaz4638
    @allandiaz4638 8 месяцев назад

    Beautiful feature, sadly we need to activate "Experimental Web Platform features" and it can't be possible on my current pro project.
    As soon as possible, I wish used this feature !
    Thanks for your video mate :D

  • @ukyoize
    @ukyoize 8 месяцев назад

    Can't wait for this to be more widespread

  • @user-ki7qu4sc3z
    @user-ki7qu4sc3z 9 месяцев назад +3

    What if we want to show it on hover ?

  • @User-404
    @User-404 4 месяца назад

    You the best, comm for the algoritm, i need this later!

  • @khoihoang8888
    @khoihoang8888 4 месяца назад

    Is there link for the final advanced example on codepen or somewhere?

  • @xdarrenx
    @xdarrenx 9 месяцев назад

    Does it work with a Ref from another library, most frameworks and such used their own reference system for performance/sanity reasons within their own framework, how do we bind 2 elements without hardcoding Id's on the element, and if possible popover as well, hwo can we otherwise track binds in big applications using this among separated components?

  • @qwertt1461
    @qwertt1461 9 месяцев назад

    with the popover attribute and anchor function you had my curiosity, with the hand icons following along the input fields and graph bars you had my interest

  • @milanm6538
    @milanm6538 9 месяцев назад

    @WebDevSimplified, great job! Can you give us a link to code examples?

  • @adityanayak20
    @adityanayak20 9 месяцев назад +1

    Looks like csssimplified coming soon next year

  • @lewisone
    @lewisone 9 месяцев назад

    That's pretty cool.