At Last! Simple details/summary animation with pure CSS

Поделиться
HTML-код
  • Опубликовано: 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  22 часа назад +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 17 часов назад +2

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

    • @doug7897
      @doug7897 6 часов назад

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

  • @simeleon
    @simeleon 10 часов назад

    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 10 часов назад

    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  22 часа назад +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 23 часа назад +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 2 часа назад

    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 22 часа назад

    Asked and answered! Thank you.

  • @curtiswilcox808
    @curtiswilcox808 4 часа назад

    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 6 часов назад

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

    • @curtiswilcox808
      @curtiswilcox808 4 часа назад

      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  22 часа назад

      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  22 часа назад +1

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

  • @AndreiLechovoleaConsilier
    @AndreiLechovoleaConsilier День назад

    Wonderful

  • @andrewwerth8312
    @andrewwerth8312 9 часов назад

    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  22 часа назад +2

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

    • @gavriel_adi
      @gavriel_adi 14 часов назад +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  22 часа назад +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 5 часов назад

      @@Killyspudful Nice!

    • @muhdkamilmohdbaki7054
      @muhdkamilmohdbaki7054 5 часов назад

      @@KevinPowell Cool!

  • @AmanpreetSinghCHD
    @AmanpreetSinghCHD 14 часов назад

    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 11 часов назад

    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  22 часа назад +1

      One Dark Pro Var Night :)

    • @PicSta
      @PicSta 15 часов назад

      @@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 19 часов назад

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

    • @vvrath
      @vvrath 15 часов назад

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

    • @geforcesong
      @geforcesong 15 часов назад +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 12 часов назад

      @@geforcesong that's fair

  • @userj-s2000
    @userj-s2000 День назад

  • @mtranchi
    @mtranchi 13 часов назад

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

  • @handcoding
    @handcoding 22 часа назад

    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  22 часа назад +1

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

    • @bmehder
      @bmehder 20 часов назад +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  22 часа назад +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 😕