At Last! Simple details/summary animation with pure CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ต.ค. 2024

ความคิดเห็น • 66

  • @CSSWeekly
    @CSSWeekly วันที่ผ่านมา +21

    Thank you so much for mentioning my video and for your kind words about CSS Weekly. Your support means a lot, Kevin! 💙

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      Thanks for making awesome CSS content!

  • @chrisbolson
    @chrisbolson วันที่ผ่านมา +23

    Another great video, Kevin.
    You can get the details to automatically close when another one is opened by giving each of them the same name. According to caniuse this currently has 83.12% browser support.

    • @acubley
      @acubley 21 ชั่วโมงที่ผ่านมา +2

      TY TY TY. This makes them act like radio buttons, you can only have one selected at a time. 👍

    • @doug7897
      @doug7897 9 ชั่วโมงที่ผ่านมา

      While nice to have, I've had too many clients/users complain about not being able to have multiple open at once.

  • @simeleon
    @simeleon 14 ชั่วโมงที่ผ่านมา

    thank you Kevin, you make CSS so much fun. I love your attention to details, small touch on list-style-position makes makes big diffrence in UI. Keep going!

  • @xXYourShadowDaniXx
    @xXYourShadowDaniXx วันที่ผ่านมา +15

    Should probably add a disclaimer that people will not be able to test this without Chrome 131+ currently. Otherwise great video!

    • @vvrath
      @vvrath วันที่ผ่านมา +1

      thanks, I was losing my mind for a minute there and then I tested it in canary

  • @pascalmaranus
    @pascalmaranus 14 ชั่วโมงที่ผ่านมา

    I had just looked up your previous video about animating auto height just a few hours prior. The trick is basically the same (for the animation part at least). So it's quite a coincidence that you end up putting out this video on the same day 😄

  • @keessonnema
    @keessonnema วันที่ผ่านมา +2

    We use "accordion" blocks a lot for our websites, and I know this is unrelated, but I just now discovered details/summary. This is going to make life so much easier! Thanks a lot.

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      Look into giving them all the same name, then only one will be opened at a time as well :)

  • @proudyy
    @proudyy วันที่ผ่านมา

    Playing with a drawer and this comes out. Pure gold to know!

  • @XCanG
    @XCanG วันที่ผ่านมา +2

    Considering that you use very new features I wish that you use nested CSS instead of this. Nested CSS is so easy to adapt and change and it's easier to port because of the nesting as well. For readability it also help to see what in what is being nested. It have better browser support that many rules used here.

  • @potrosanjuan
    @potrosanjuan 6 ชั่วโมงที่ผ่านมา

    Thanks a lot, we all know your video is going to be useful before hand

  • @Killyspudful
    @Killyspudful วันที่ผ่านมา

    Zoran Jambor is a good guy and his channel is well worth following too.

  • @jenstornell
    @jenstornell วันที่ผ่านมา

    High level skills there Kevin! I learned a thing or two. 🎉😊

  • @bmehder
    @bmehder วันที่ผ่านมา

    Asked and answered! Thank you.

  • @curtiswilcox808
    @curtiswilcox808 7 ชั่วโมงที่ผ่านมา

    The Codepen version in the description has as a typo that not only prevents the transition from working, it prevents the details contents from being visible when its opened (there's also so extraneous JavaScript in that pane). This selector:
    details:open::details-content
    should be:
    details[open]::details-content

  • @deatho0ne587
    @deatho0ne587 วันที่ผ่านมา

    Almost think "interpolate-size: allow-keywords;" just needs to become the default for all browsers, also allow-discrete.
    Yes it might cause old sites to look slightly better and fight a bit with the JS (which should win I think)

  • @JosephCodette
    @JosephCodette วันที่ผ่านมา +5

    Cool ! That is going to be awesome in 10 years when the support is better 😂😉

  • @doug7897
    @doug7897 9 ชั่วโมงที่ผ่านมา

    Been a hot minute, is accessibility on getting any better or is the custom accordion still the best option?

    • @curtiswilcox808
      @curtiswilcox808 7 ชั่วโมงที่ผ่านมา

      VoiceOver+Safari for Mac is kind of buggy operating details/summary elements; two open bugs are expand/collapse states aren't announced when they change and focus moves off the summary element when you activate it.

  • @erchenstein
    @erchenstein วันที่ผ่านมา

    Very cool video! thx
    I'd be cool if you could make a video sometime in the future about the details element's name attribute? By using this attribute and rearranging the details elements horizontally you can make pure css tabs without the need of employing hacks including radio labels. With you animation it would be extra cool:

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา

      It actually has decent support now too! Better than some of the things I was doing in this video!

  • @erickdavid4257
    @erickdavid4257 วันที่ผ่านมา +4

    Would it be “safe” to add `transition-behavior: allow-discrete` and `interpolate-size: allow-keywords` to our CSS reset?

    • @rankarat
      @rankarat วันที่ผ่านมา

      Following.

    • @Killyspudful
      @Killyspudful วันที่ผ่านมา

      Yes - CSS that a browser doesn't recognise will do nothing - it doesn't break or throw errors.

    • @CSSWeekly
      @CSSWeekly วันที่ผ่านมา +2

      There are some cases where both could have unwanted consequences in existing projects if you're already handling what they do manually, for example, using JavaScript.
      I think it's perfectly reasonable to include both in your reset for new projects, but for existing projects, I would double-test my transitions. 🙂

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      Like @CSSWeekly said, for new projects, I'd definitely use them, yup!

  • @AndreiLechovoleaConsilier
    @AndreiLechovoleaConsilier วันที่ผ่านมา

    Wonderful

  • @andrewwerth8312
    @andrewwerth8312 13 ชั่วโมงที่ผ่านมา

    Are the semantics of summary/details such that this shouldn't be used for, say, dropdown menus? Or is it fair game as long as it works?

  • @claudschgi4794
    @claudschgi4794 วันที่ผ่านมา +5

    Hey Kevin! Great Video! I am big fan of the no more JS for such simple microinteraction :) juhu

  • @gavriel_adi
    @gavriel_adi วันที่ผ่านมา +1

    The question is how do you make the transition effect in the dialog element as well?
    of closing and opening..

    • @gavriel_adi
      @gavriel_adi วันที่ผ่านมา +2

      .Dialog{
      max-width: 90%;
      width: 350px;
      background: var(--color-fff);
      color: var(--color-000);
      padding: 20px;
      border-radius: 10px;
      border: none;
      box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;
      transition: opacity 0.4s cubic-bezier(0.4, 1.6, 0.4, 0.8),
      scale 0.4s cubic-bezier(0.4, 1.6, 0.4, 0.8), overlay 0.4s allow-discrete,
      display 0.4s allow-discrete;
      opacity: 0;
      scale: 0;
      &::backdrop {
      transition: display 0.4s allow-discrete, overlay 0.4s allow-discrete,
      background-color 0.4s;
      }
      &[open] {
      opacity: 1;
      scale: 1;
      }

      &[open]::backdrop {
      background: rgba(0, 0, 0, 0.3);
      }
      }
      @starting-style {
      .Dialog[open] {
      opacity: 0;
      scale: 0;
      &::backdrop {
      background-color: hsl(0 0 0 / 0);
      }
      }
      }

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +2

      Already recorded a video on that, coming out in 2 weeks I think :D

    • @gavriel_adi
      @gavriel_adi 18 ชั่วโมงที่ผ่านมา +1

      @@KevinPowell This is one of the important things, but here is a code that worked for me, look at the comment above, it works like crazy but you need to know it because I found almost no information about it on the net

  • @muhdkamilmohdbaki7054
    @muhdkamilmohdbaki7054 วันที่ผ่านมา +1

    Kind sir, I am wondering if the shadow dom (shadow-root details::details-contents stuffs) is browser dependent because it looks like it is internal/browser implementation? 🤔 I think it would be great to know if the code we are using browser dependent or not. Thank you very much.

    • @Killyspudful
      @Killyspudful วันที่ผ่านมา +1

      It isn't supported across other browsers yet - but when it *is*, the pseudo-element names like '::details-content' should be the same.

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      it is an internal implementation at the moment, but it's part of the spec and it'll work in other browsers as well, once they add support for it :)

    • @muhdkamilmohdbaki7054
      @muhdkamilmohdbaki7054 9 ชั่วโมงที่ผ่านมา

      @@Killyspudful Nice!

    • @muhdkamilmohdbaki7054
      @muhdkamilmohdbaki7054 9 ชั่วโมงที่ผ่านมา

      @@KevinPowell Cool!

  • @AmanpreetSinghCHD
    @AmanpreetSinghCHD 17 ชั่วโมงที่ผ่านมา

    How can we update it to be on hover since these days a lot of themes use details for creating dropdown menu would love to see how it can be managed as a menu (mega menu) would be a cool tutorial :)

  • @LokiDaFerret
    @LokiDaFerret 15 ชั่วโมงที่ผ่านมา

    Why isn't the default for interpolate-size set to allow-keywords? There must be a good reason otherwise it doesn't make sense for it to be anything else??!!

  • @PicSta
    @PicSta วันที่ผ่านมา

    Hey Kevin, can you say which VSC Theme that is? Looks stunning to me. Thanks in advance.

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      One Dark Pro Var Night :)

    • @PicSta
      @PicSta 18 ชั่วโมงที่ผ่านมา

      @@KevinPowell Thanks a lot. I had One Dark Pro, but not "Var Night".

  • @matheussouza7758
    @matheussouza7758 วันที่ผ่านมา

    Nice video.
    How could you style a shadow-dom element when styling details::details-content? i thought that was not possible.

    • @juj1988
      @juj1988 วันที่ผ่านมา +1

      That’s the pseudo selector

    • @simonhartley9158
      @simonhartley9158 วันที่ผ่านมา +2

      Pseudo elements exposed by the shadow dom are styleable. For a normal web component, that would be via ::part or ::slotted, but the browser can do its own magical things.

    • @matheussouza7758
      @matheussouza7758 วันที่ผ่านมา

      @@simonhartley9158 thanks!

  • @geforcesong
    @geforcesong 22 ชั่วโมงที่ผ่านมา

    Really wanted to see it's supported 100% browsers.Otherwise, can't use it on production

    • @vvrath
      @vvrath 19 ชั่วโมงที่ผ่านมา

      It gracefully degrades to the normal behaviour. so, no reason not to use it now?

    • @geforcesong
      @geforcesong 18 ชั่วโมงที่ผ่านมา +1

      @ well we have other ways to achieve this perfectly across the browsers. No need to do this only for simplify the code

    • @vvrath
      @vvrath 16 ชั่วโมงที่ผ่านมา

      @@geforcesong that's fair

  • @userj-s2000
    @userj-s2000 วันที่ผ่านมา

  • @mtranchi
    @mtranchi 16 ชั่วโมงที่ผ่านมา

    For anyone who tries playing with this, Chrome 131 won't be GA until Nov 6th (2024).

  • @handcoding
    @handcoding วันที่ผ่านมา

    2:53 - “interpolate-size” literally only works in Chrome and nowhere else. This is a nonstarter.

  • @TriumphAidenojie
    @TriumphAidenojie วันที่ผ่านมา

    I tried your code for animating height auto but it didn't work for me. Kindly help me. Like if you had similar issues. I'd really love for Kevin to notice this comment. Thanks

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      Do check the browser support, some of this is very new :)

    • @bmehder
      @bmehder วันที่ผ่านมา +1

      Someone mentioned in a comment that you will need Chrome 131 or higher.

  • @Black1991Star
    @Black1991Star วันที่ผ่านมา

    Dose it work in Safary ?

    • @mrleonmoff6523
      @mrleonmoff6523 วันที่ผ่านมา

      Just hopping in to get the answer too when you get it

    • @chrisbolson
      @chrisbolson วันที่ผ่านมา

      ​ @Black1991Star I don't think so. According to caniuse, ::details-content is only available on Chrome 131-133.
      I was testing this out on my Mac and, as it is older, I can't update Chrome past 128 (at least at the moment)

    • @dhaloh
      @dhaloh วันที่ผ่านมา

      No.

    • @KevinPowell
      @KevinPowell  วันที่ผ่านมา +1

      Not yet. I talked about browser support and linked to the tables in the description :)

  • @ukyo6195
    @ukyo6195 วันที่ผ่านมา

    Way to complicated for a simple transition 😕