Animate details & summary with a few lines of CSS

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

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

  • @CSSWeekly
    @CSSWeekly หลายเดือนก่อน +42

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

    • @KevinPowell
      @KevinPowell  หลายเดือนก่อน +3

      Thanks for making awesome CSS content!

    • @CSSWeekly
      @CSSWeekly หลายเดือนก่อน +1

      @@KevinPowell ❤

    • @YasirKhan-nn2ss
      @YasirKhan-nn2ss 27 วันที่ผ่านมา +1

      @cssweakly hi

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

      @@YasirKhan-nn2ss Hi Yasir! 👋

  • @chrisbolson
    @chrisbolson หลายเดือนก่อน +26

    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 หลายเดือนก่อน +3

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

    • @doug7897
      @doug7897 หลายเดือนก่อน +1

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

    • @acubley
      @acubley หลายเดือนก่อน

      @@doug7897 My use was (and there is prob an easier way) a list of details > div > details, etc. with the divs popping out sideways. This just cuts out some JS.

  • @xXYourShadowDaniXx
    @xXYourShadowDaniXx หลายเดือนก่อน +26

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

    • @vvrath
      @vvrath หลายเดือนก่อน +2

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

  • @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

  • @keessonnema
    @keessonnema หลายเดือนก่อน +3

    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  หลายเดือนก่อน +4

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

  • @CyberTechBits
    @CyberTechBits 16 วันที่ผ่านมา

    Absolutely fantastic! I have a product catalog I am going to implement this with using nested details/summary. I was working on the prototype while watching your video and it is working beautifully! This will replace a lot of nested ul/li and javascript to expand collapse products items in my catalog. Thanks Kevin!

  • @simeleon
    @simeleon หลายเดือนก่อน

    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!

  • @user-848
    @user-848 หลายเดือนก่อน

    Дуже дякую за інформування про нові властивості CSS! Надкорисна інформація. Чекаємо з нетерпінням оновлення браузерів. А ваш урок вже пішов на користь. Впровадив на чинному сайті на роботі. Дякую ще раз!

  • @proudyy
    @proudyy หลายเดือนก่อน

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

  • @pascalmaranus
    @pascalmaranus หลายเดือนก่อน

    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 😄

  • @XCanG
    @XCanG หลายเดือนก่อน +3

    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.

  • @Killyspudful
    @Killyspudful หลายเดือนก่อน

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

  • @potrosanjuan
    @potrosanjuan หลายเดือนก่อน

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

  • @jenstornell
    @jenstornell หลายเดือนก่อน

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

  • @plusalphadesign
    @plusalphadesign 18 วันที่ผ่านมา

    Worked like a charm, thanks! 🙌 But I'd update the title to clarify Chrome 131+ only - this got me too.

  • @djmtype
    @djmtype หลายเดือนก่อน +1

    @KevinPowell your codepen appears to be broken either by a typo or maybe a spec change since this video? Codepen, line 24, `details:open::details-content` but works with `details[open]::details-content` instead.

  • @bmehder
    @bmehder หลายเดือนก่อน

    Asked and answered! Thank you.

  • @JosephCodette
    @JosephCodette หลายเดือนก่อน +6

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

  • @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 หลายเดือนก่อน +3

      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  หลายเดือนก่อน +3

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

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

      @@KevinPowell My question is regarding implications with having those rules applied globally with the star selector. Like Adam Wathan’s infamous `min-width: 0` rule…

  • @MortenAndersen-hjemmesider
    @MortenAndersen-hjemmesider หลายเดือนก่อน +1

    For some reason I can't use details::details-content { ...} I can see it in devtools but my css takes no effect. (Latest Mac OS, Latest Chrome)

  • @doug7897
    @doug7897 หลายเดือนก่อน

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

    • @curtiswilcox808
      @curtiswilcox808 หลายเดือนก่อน

      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.

  • @andrewwerth8312
    @andrewwerth8312 หลายเดือนก่อน

    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?

  • @AndreiLechovoleaConsilier
    @AndreiLechovoleaConsilier หลายเดือนก่อน

    Wonderful

  • @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!

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

    Using Chrome Version 130 but I can only see a details-content id on the slot, it doesn't say psuedo="details-content"? Trying to style it has no effect either. I cant work out what I am doing wrong.

  • @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 หลายเดือนก่อน +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 หลายเดือนก่อน

      @@Killyspudful Nice!

    • @muhdkamilmohdbaki7054
      @muhdkamilmohdbaki7054 หลายเดือนก่อน

      @@KevinPowell Cool!

  • @LokiDaFerret
    @LokiDaFerret หลายเดือนก่อน

    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??!!

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

    Anyone know if there's a polyfill for this for current browser support?

  • @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)

  • @AmanpreetSinghCHD
    @AmanpreetSinghCHD หลายเดือนก่อน

    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 :)

  • @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 หลายเดือนก่อน

      @@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!

  • @claudschgi4794
    @claudschgi4794 หลายเดือนก่อน +5

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

  • @userj-s2000
    @userj-s2000 หลายเดือนก่อน

  • @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 :)

  • @geforcesong
    @geforcesong หลายเดือนก่อน

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

    • @vvrath
      @vvrath หลายเดือนก่อน

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

    • @geforcesong
      @geforcesong หลายเดือนก่อน +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 หลายเดือนก่อน

      @@geforcesong that's fair

  • @udenichisamson9083
    @udenichisamson9083 7 วันที่ผ่านมา

    is it only me, because chrome don't preference in the settings

  • @mtranchi
    @mtranchi หลายเดือนก่อน

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

  • @ikidesign-nl
    @ikidesign-nl 11 วันที่ผ่านมา

    Doesn't work for me

  • @dalransom
    @dalransom 9 วันที่ผ่านมา

    interpolate-size: allow-keywords? Makes no sense. Hopefully it'll be reworded to something more intuitive. Perhaps 'interpolate-size: interpolate;' would make more sense.

  • @ukyo6195
    @ukyo6195 หลายเดือนก่อน

    Way to complicated for a simple transition 😕