A powerful CSS display property that no one talks about

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

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

  • @NemanjaPantos
    @NemanjaPantos 2 ปีที่แล้ว +4

    Funny story. A few days ago I was working on an ugly project, and my job was to style it, without changing the structure. And I had some P tag with icon, text (without wrapper tag), and link inside.
    And they want to get a grid from it with two rows, two columns, an icon to span with two rows...
    I was breaking my head, and I gave up in the end. Usually, I can change the structure, and fix it, but here I was stuck.
    A couple of hours later, while I was having dinner, I turned on youtube on my mobile, and your video was the first one. And the video was about the same problem that I had :D
    I have 15+ years of CSS experience, and I never had a problem like this, and at the same day, I got recommended video with a solution for my problem :D

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

      This happens to me all the time! I’ll be working on something, getting stuck and KPow drops a video that relates perfectly to my problem. It’s so serendipitous!!

  • @ARTHURVANPAS
    @ARTHURVANPAS 2 ปีที่แล้ว +101

    Wow I've only just realized he says front-end friends in the beginning. I always thought he said friend and friends which, admittedly, is weird, but I don't know every saying, so yeah, that happened

    • @eqprog
      @eqprog 2 ปีที่แล้ว +17

      🤯 I always thought he was saying “friend and friends” as well. I thought it was neat actually. Like, saying hello to me specifically and then everyone else.

    • @fpul
      @fpul 2 ปีที่แล้ว +8

      Same. He doesn't really pronounce the t as strong as front so I had no idea!

    • @seanandrew4457
      @seanandrew4457 2 ปีที่แล้ว +6

      Hahaha never realised until you mentioned it....

    • @SamCrowetheCreativeCrowe
      @SamCrowetheCreativeCrowe 2 ปีที่แล้ว +2

      Mind blown! It has always been a sort of affirmation for me. Like the scene from that old show Touched by An Angel where the actress looks into the camera and says in that rich Irish accent, "God loves you". I pretended it was directed at me, like I am the friend and everyone else is friends. Life has less meaning now. Hahaha! Still great content and the hoodie is awesome too from the merch below!

    • @GavHTFC
      @GavHTFC 2 ปีที่แล้ว +4

      I've noticed him annunciating it a lot more recently, I imagine for precisely this reason as I was in the same boat!

  • @bernardobeninifantin509
    @bernardobeninifantin509 2 ปีที่แล้ว +2

    Came here for the display: contents, ended up getting to know more css complex selectors. YES!

  • @KenPetri
    @KenPetri 2 ปีที่แล้ว +3

    Kevin, thanks for always talking about the accessibility of the techniques you discuss.

  • @merotuts9819
    @merotuts9819 2 ปีที่แล้ว +4

    I recently came across this property myself while toying around with the Dev tool and then you upload this explanation video. 💛

  • @HumbertoRincon
    @HumbertoRincon 2 ปีที่แล้ว

    I stopped the video at 08:56 to get a single frame and talk about math.
    It's natural to put variables first and then numbers, like (n + 4) or (-n + 3).
    But you could agree that -just listening to your own explanation, you could understand it easier just tweaking the formulas this way:
    a) count starting from the 4th element till the end (4 + n) as you explain at 08:04 or,
    b) start at the third position and go backward to the beginning (3 - n).
    And thanks for another awesome explanation!!

  • @MasterTeeee
    @MasterTeeee ปีที่แล้ว +1

    A good use-case for this with grids, is when you need to support graceful degradation...
    If a browser (like Opera Mini) doesn't support grid, you'll likely want to have a lot more wrappers for elements, but, using those wrappers in the HTML will break your grid layout. Enter `display: contents;` to the rescue... Now you can support your basic, functional layout with boring wrappers, but in browsers that support `display: contents;` (which is most places that grid is supported, except for IE), you'll still have your nice grid layout available.

  • @gabriellundmark
    @gabriellundmark 2 ปีที่แล้ว +12

    I use display contents all the time to get rid of unnecessary (for styling purposes at least) elements an get items onto my grid or flex kebab. Sometimes on multiple levels to really unwrap something nested deeply!

    • @happyjohn1656
      @happyjohn1656 2 ปีที่แล้ว +3

      "Flex kebab" rolls off the tongue, love it! 😂
      1:25 AM
      4/6/2022

    • @SebastianZartner
      @SebastianZartner 2 ปีที่แล้ว +1

      For some use cases you may want to work with subgrid instead. Unfortunately, the only browser currently supporting it is Firefox, though, but it seems it'll come to Chrome and Safari soon, too.

  • @nomadshiba
    @nomadshiba 2 ปีที่แล้ว

    YOUR TIMING
    just what i needed

    • @nomadshiba
      @nomadshiba 2 ปีที่แล้ว

      i was making some component library, and this is just what i needed

  • @vintprox
    @vintprox 2 ปีที่แล้ว +1

    Oooooh, I already imagine it to be useful for the combo of ::after and display: contents - like those separators you see in the menus! This is incredible.

  • @Turabbo
    @Turabbo 2 ปีที่แล้ว +1

    I mosttly use display:contents to posthumously fix horrible DOM lol. I find people who aren't as passionate about UI tend to wrap things in too many containers while they're wrangling layout.
    It's also handy for component-based JS frameworks like Angular which wrap every component in a custom container. With display:contents you can free the contents of the component back out into the main flow.

  • @candym5280
    @candym5280 2 ปีที่แล้ว

    I was having trouble with this just now! I came to TH-cam to watch your videos obout grid to find my way around the problem, and find this video on my feed! Kevin you're God 🤣

  • @YurijVolkov
    @YurijVolkov 2 ปีที่แล้ว

    That was amazing! It's satisfying to find out something that I didn't know.

  • @gopalloharnew5948
    @gopalloharnew5948 2 ปีที่แล้ว +1

    It's Interesting and seems useful !

  • @tomaylott2593
    @tomaylott2593 2 ปีที่แล้ว

    oh wow! this is actually SUPER useful!

  • @Melvin420x12
    @Melvin420x12 2 ปีที่แล้ว

    This is so cool! Thank you for these great examples

  • @myrinaDM
    @myrinaDM 2 ปีที่แล้ว

    You are great! Thank you for your time and efforts to explain us.

  • @ChrispyChris3
    @ChrispyChris3 2 ปีที่แล้ว

    Great video and nice explanations as always!

  • @errormaker1
    @errormaker1 2 ปีที่แล้ว

    this is really good for customizing components from libraries

  • @jugibur2117
    @jugibur2117 2 ปีที่แล้ว

    Great stuff, thanks for sharing!

  • @WellSaint001
    @WellSaint001 2 ปีที่แล้ว

    there's a lot of info in this video! thanks kevin!

  • @n_mckean
    @n_mckean 2 ปีที่แล้ว +5

    Hey Kevin. A lot of times we need to refer back to your videos to find something we've watched before - especially is sending them to others. Can you keep this in mind when setting your video titles? "A powerful CSS display property that no one talks about" gives me no hint in a month's time what it involved, to jog my memory.

    • @gabriellundmark
      @gabriellundmark 2 ปีที่แล้ว

      This makes a lot of sense for viewers, but unfortunately not for content creators. Interesting titles are key to generating views. Check out Veritasium's great video on this topic.

    • @n_mckean
      @n_mckean 2 ปีที่แล้ว

      @@gabriellundmark It get that, but there can be a balance.

    • @n_mckean
      @n_mckean 2 ปีที่แล้ว

      I've only now seen the image helps. I guess I've had to go with that rather than a search.

  • @AmodeusR
    @AmodeusR 2 ปีที่แล้ว +1

    I must tell this solved me sometime headaches! Well, maybe not that much, but enough to find it cool and as always, thank you for all you do!
    I wanted to use a Button component I had made with the semantic of a link tag, I couldn't just change to a "a" tag, I would need to style everything again, and also I had the button with another button in a flex container, which embracing the button with the tag broke the 50/50 flow. So I just threw the "display: contents" in the a tag and it came back to the way I wanted it to be!
    *Noice*👌

  • @asesoriasdemateyfisicasupe3085
    @asesoriasdemateyfisicasupe3085 2 ปีที่แล้ว

    Thank you
    I´m your student in Scrimba. Great course

  • @giocaonguyen
    @giocaonguyen 2 ปีที่แล้ว

    It's really interesting! Thank you for your great content.

  • @mediocreTyler
    @mediocreTyler 2 ปีที่แล้ว

    Thanks for the useful info, much appreciated friend.

  • @KawazoeMasahiro
    @KawazoeMasahiro 2 ปีที่แล้ว +2

    I've noticed that the way text gets placed when using display content in a flex box doesn't always behave as expected. Even in your example, it appears like the text's basline is lost/changed. It is very easy to see if you compare the vertical position of the logo with the rest of the links between 5:30 and 9:20 . Can you elaborate a bit on this?

    • @SebastianZartner
      @SebastianZartner 2 ปีที่แล้ว +1

      In this specific case (see Kevin's Codepen at codepen.io/kevinpowell/pen/dyJRJjO). The reason for the misalignment is that the s have a bigger font size and line height than the logo. The issue is unrelated to display: contents. In flexbox layout, the flex items get stretched by default and the text is placed at the top of the element. To fix that, you can apply an align-items: center to the flex container to center them or align-items: baseline to align them on their common baseline. See developer.mozilla.org/en-US/docs/Web/CSS/align-items for more info on that.
      Another point you need to consider using display: contents, which Kevin mentions in his video, is that it causes the element not to generate a box. That means that layout related properties like margin, border or padding have no effect on it. So if they only contain text, you won't be able to change its layout, only its style like font-size, color, etc.

    •  2 ปีที่แล้ว

      @@SebastianZartner The link does not work and throws a 404 error.

  • @ed1nh0
    @ed1nh0 2 ปีที่แล้ว +4

    Really interesting content, as always! It's a bit challenging to use but I do like it! About the flex order you could make use of tab-index (on clickable elements) to deal with it, don't you?

  • @_BangDroid_
    @_BangDroid_ ปีที่แล้ว

    Nice explanation, thanks!

  • @choz8358
    @choz8358 2 ปีที่แล้ว

    Your content is amazing, and you too.

  • @zooneyl2248
    @zooneyl2248 2 ปีที่แล้ว

    9:55 Why would the tab start at the logo since the logo order is "2" in css, even though the logo comes first in the html?

  • @sanjibchanda21
    @sanjibchanda21 2 ปีที่แล้ว

    Awesome css tricks, thank you sir ❤

  • @inklingboi8431
    @inklingboi8431 2 ปีที่แล้ว

    Nice video! That seems like a really cool property, and I think you wrote display: contents wrongly in the description btw (as display: content)

  • @marwenlabidi_dev
    @marwenlabidi_dev 2 ปีที่แล้ว

    You always amaze me

  • @AlexanderCerutti
    @AlexanderCerutti 2 ปีที่แล้ว

    Kevin repeated grid columns so hard that even "it" in the phrase above became double lol

  • @CirTap
    @CirTap 2 ปีที่แล้ว

    Probably the main reason this was/is not used, is very likely MSIE -- as always. There have also been implementation bugs in evergreen browsers for years that resulted in severe a11y issues with the element being virtually "ripped" from the DOM.
    This property fundamentally changes how markup structure and css work together and there is no trivial fallback or workaround in CSS that can be used.
    I would've loved to use this years ago for every other grid structure, but this property came with too much trouble and requires extra work to make both IE users *and screen readers* happy.
    AFAIK the a11y issues have been solved by now, and with IE being officially dead, we can try to use this on sites where IE users are virtually non existent, so as always: check your logs and analytics first.

  • @denisfok1699
    @denisfok1699 2 ปีที่แล้ว

    interesting css property, thank you!

  • @developer_hadi
    @developer_hadi 2 ปีที่แล้ว +4

    you're awesome

  • @DennisRLing
    @DennisRLing 2 ปีที่แล้ว

    Kevin, I am just learning css with grid, flex etc. What makes it useful for me watching your videos is when you put ALL your code up, like on codepen. I can then fork it and start playing with your code, making changes and seeing how those changes effect the the outcome and adding my site coding. I am presently watching this and adding your code to VSC... however, since my css is slowly coming together I am missing the code you pre-made in your css file... body etc. SO, I'm not seeing what you are showing as far as all the css formatting. Maybe I'm dyslectic, not really sure, but I've always done better by visual learning as apposed to reading. So, in this case I like to grab html and css files and just start making a change and then looking at the browser to see that change. Crazy, I know, but that's how I learn. I have a bunch of websites that I started for friends years ago that I am now looking to update with things like grid, flex, animation using transform and transition etc etc. I see a great navbar on the web so I start googling how to do it... I always wind up watching your TH-cam channel. All those sites I designed never used any CSS. I used Dreamweaver. Anywho, I'm starting to babble. Geez, was there a ? in there somewhere?

  • @animelover8185
    @animelover8185 2 ปีที่แล้ว +1

    Sir I m your big fan...😊

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +1

      Happy to hear that 😊

  • @kvetoslavnovak423
    @kvetoslavnovak423 2 ปีที่แล้ว

    Very interesting . Thank you. Do you think that footnotes would be good use-case for this as well? For example a text where footnotes tags are within but rather should be displayed visually bellow the text?

  • @frankroos1167
    @frankroos1167 2 ปีที่แล้ว +1

    This feels like it can be used to get subgrid like behavior, to some extent.
    Gonna have to play with this a bit to see how far it will go.

  • @rodbrowning
    @rodbrowning 2 ปีที่แล้ว

    I have a question. You said Mozilla had fixed the bug, at 10:35 in the video, and it happened a few days ago. How do you have access to this news? There is some news letter or you consult it by searching? And the last one. Where can I get more advanced stuff on the web, beyond you channel of course?
    Thanks again.

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +1

      I follow the bug reports on some things, so I get emails as they're fixed. You can Google the name of the feature and "bug report" and find them for all the browsers.

  • @dave6012
    @dave6012 2 ปีที่แล้ว

    Another set of 💎💎💎

  • @eggkookoo
    @eggkookoo 2 ปีที่แล้ว +1

    Does anyone else think Kevin has somehow weaponized "my friend and friends"?

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว

      🤣🤣 - I'd have failed pretty hard at it, since it isn't what I say, it's just what everyone hears (including TH-cam's auto-captions), lol

    • @HeyFang
      @HeyFang 2 ปีที่แล้ว

      well I heard "my front end friends"

    • @eqprog
      @eqprog 2 ปีที่แล้ว

      @@KevinPowell it’s like a mr rogers thing. You’re saying hello to ME!

    • @eggkookoo
      @eggkookoo 2 ปีที่แล้ว

      @@KevinPowell Well now I'm just embarrassed...

  • @SebastianZartner
    @SebastianZartner 2 ปีที่แล้ว

    Kevin, it would be super cool if you linked your Codepens under your videos so watchers can reproduce the things you're doing in them!

  • @A_Lesser_Man
    @A_Lesser_Man 2 ปีที่แล้ว

    display: contents - that's a new one on me. tell me more, obi wan

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

    I was looking for the exact opposite, sibling acting as a child, which turns out to be the exact same problem lol.

  • @Noobificado
    @Noobificado 2 ปีที่แล้ว +1

    Getting child to behave as a sibling, or how i call it: the Alabama special.

  • @danialranjbar9805
    @danialranjbar9805 2 ปีที่แล้ว

    Kevin, I have a question. when I have my grid-template-area setup, different cells with different content widths get different alignments and justifications. And I'm not able to impose a rule from the parent (while using grid-area) for all children with different content widths to look the same. This is absolutely possible using grid-template-columns. could you make a video and explain how are we able to do so with grid-area only?

    • @DrugedSheep
      @DrugedSheep 2 ปีที่แล้ว +1

      You can definitely specify cell sizes directly with grid-template-areas.
      grid-template-areas: "a b" 1fr "c d" 1fr / 1fr 1fr;
      This will make both columns the same width and both rows the same height.

    • @danialranjbar9805
      @danialranjbar9805 2 ปีที่แล้ว

      @@DrugedSheep i searched your clue and got it thanks

  • @adrianlambrese
    @adrianlambrese 2 ปีที่แล้ว

    Amazing!!!

  • @dasten123
    @dasten123 2 ปีที่แล้ว

    I'm always surprised how much CSS stuff there is that I have never heard about

  • @budosfasz
    @budosfasz 2 ปีที่แล้ว

    Hi, in HTML what is that unpkg lines? I know what are they doing, but where it is come from? What is unpkg?

  • @jozefrzadkosz5945
    @jozefrzadkosz5945 2 ปีที่แล้ว

    Once I asked about this property on stackoverflow and someone pointed me out that this property has some real issues about a11y depending screen readers, do you know something about this? And still safari is not supporting this fully so writing some workarounds for this one is really painful

  • @edwardgray6167
    @edwardgray6167 2 ปีที่แล้ว

    Would wrapping this code in @media screen{ } solve the accessibility issues?

  • @re.liable
    @re.liable 3 หลายเดือนก่อน

    Found this out while trying to include a button in a paragraph, but have its text wrap with the paragraph text. If y'all have a better solution for this, please let me know

  • @JU315TMC
    @JU315TMC 2 ปีที่แล้ว

    🔥🔥🔥

  • @MrMairu555
    @MrMairu555 2 ปีที่แล้ว +1

    What happened to all the smooshing? Not much going on any more! 🤣🤣
    I've been doing loads of grid/flex stuff lately to get text beside images, so will give this a go! Thank you.

  • @andrewphi4958
    @andrewphi4958 2 ปีที่แล้ว +1

    Golden rule: When writing something new, keep compatibility. If you don't want to be hated by owners of forcibly-obsolete devices and browsers.

    • @rjsmith2007
      @rjsmith2007 2 ปีที่แล้ว

      Goodbye old browsers

    • @SebastianZartner
      @SebastianZartner 2 ปีที่แล้ว +1

      That's a very good point! Creating a website, you should always be backwards compatible. I'd really like to see Kevin emphasize that and show how to work around unsupported features. I imagine, for display: contents it'll be very hard to create a proper way of displaying your contents for browsers that don't support it.

  • @itsPenguinBoy
    @itsPenguinBoy 2 ปีที่แล้ว +1

    Awww, I used nth of type for re-ordering items in a flex layout recently and didn't realise until this video that it causes accessibility issues 🤦🏻‍♀️
    It kinda feels dangerous that re-ordering is bso easy given this downfall.

  • @alvaroprietovideos
    @alvaroprietovideos 2 ปีที่แล้ว

    You are CSS evangelist King 👑

  •  2 ปีที่แล้ว

    It doesn't work even under the fox of the header. Any general tips?

  • @paul.prestidge
    @paul.prestidge 2 ปีที่แล้ว

    So cool!

  • @hughclarke8504
    @hughclarke8504 2 ปีที่แล้ว +1

    Hello Kevin. Great videos. Kevin would you great a video on forms like a contact us that sends the content to the owner of the website with recapture.

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +2

      The problem with forms is it really depends on the tech stack your using. I could look at a simple way to do it though, it just might not be the best solution for everyone... maybe I could look at 2 or 3 🤔

    • @hughclarke8504
      @hughclarke8504 2 ปีที่แล้ว +2

      @@KevinPowell that is one of the reason why html for me feels limiting. Any help would be greatly appreciated.

    • @delulu6969
      @delulu6969 2 ปีที่แล้ว

      @@hughclarke8504 HTML is the markup of your frontend page. Sending emails happens on the server. Technically, you could use anchor element with email href but that will use the default email client of the user.

  • @rodbrowning
    @rodbrowning 2 ปีที่แล้ว

    My answer for the introduction was. I absolutely never heard about what you mean, fuck I'm totally confused, I want to quit. But in the end I got what you mean.

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +1

      Oh no, don't quit! This is a bit more advanced stuff, don't worry about it and keep on going, you've got this 💪

    • @rodbrowning
      @rodbrowning 2 ปีที่แล้ว

      @@KevinPowell I just finished the video. I've got what you mean. I gonna training it today. Thank you.

  • @zarinloosli5338
    @zarinloosli5338 2 ปีที่แล้ว

    Could this be used as a fallback for subgrid, then?

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +1

      Sort of, but it's not really the same thing. It would be really similar though, but there are a few good posts out there about how it's not really a replacement for it. Considering subgrid looks like it'll have full support in the coming months anyway, I'd just hold off, as support for this and subgrid aren't going to be very different.

    • @UBERDHOKER
      @UBERDHOKER 2 ปีที่แล้ว

      The main difference is that subgrid still renders it's own box, useful for background colours etc.. subgrid also doesn't have to inherit the entire grid definition, while this just dumps everything into the parent. You can however achieve most of subgrid using contents, (partial) inherit on grid template and custom properties

  • @justsample9185
    @justsample9185 2 ปีที่แล้ว +1

    yet another thing how to confuse most of the web devs (co-workers on the project), I see the benefit, but on the other hand, why would we make our styles more complex when there are other ways that everyone can understand (+have better browser support)

  • @EugeneKoshelev
    @EugeneKoshelev 2 ปีที่แล้ว

    Cool!

  • @steveringwood2224
    @steveringwood2224 2 ปีที่แล้ว

    This could be really useful

  • @cubx__
    @cubx__ 2 ปีที่แล้ว +3

    so exited about the topic that he forgets half of his intro sentence :D

  • @uridevmedia
    @uridevmedia 2 ปีที่แล้ว

    Wow this is great powell

  • @marcodev3375
    @marcodev3375 2 ปีที่แล้ว

    Analogies to display: react-fragment 😀

  • @SzAeBb
    @SzAeBb 2 ปีที่แล้ว +1

    display: contens is simply opposite to make display: block. In the first example (if u could edit HTML) changing block into inline would result the same :)
    Great trick.

  • @AirforcLuckyThirteen
    @AirforcLuckyThirteen 2 ปีที่แล้ว

    Whoa!

  • @zen-zeo3223
    @zen-zeo3223 2 ปีที่แล้ว

    thank you

  • @uridevmedia
    @uridevmedia 2 ปีที่แล้ว +1

    I'll love it if you could coach me on my tech journey

    • @KevinPowell
      @KevinPowell  2 ปีที่แล้ว +1

      I wish I could too! I get asked a lot, and can't mentor everyone sadly. Come and join my Discord though, so many helpful people there!

    • @uridevmedia
      @uridevmedia 2 ปีที่แล้ว

      Wow, getting a reply from you means alot
      I've joined your discord channel since January or February

  • @onnot701
    @onnot701 2 ปีที่แล้ว

    very interesting

  • @clintongallagher
    @clintongallagher ปีที่แล้ว

    Just get out of bed this morning? ROFL

  • @fluntimes
    @fluntimes 2 ปีที่แล้ว

    This is voodoo. Amazing what is possible with layouts these days.

  • @anantgupta1188
    @anantgupta1188 2 ปีที่แล้ว

    great!

  • @1ups_15
    @1ups_15 2 ปีที่แล้ว +1

    sweet home alabama

  • @dimofamo
    @dimofamo 2 ปีที่แล้ว

    🤯

  • @sovereignlivingsoul
    @sovereignlivingsoul ปีที่แล้ว

    seems to be a select use, but a nifty trick all the same

  • @mathialagant
    @mathialagant 2 ปีที่แล้ว

    He has a lowkey peter griffin voice

  • @user-ms8ei9le7x
    @user-ms8ei9le7x 2 ปีที่แล้ว

    Kevin thank 🎓 nth-of-type(....)

  • @TheUnknownFactor
    @TheUnknownFactor 2 ปีที่แล้ว

    This is really cool, but I do think you're being overly optimistic about being able to use this already. As a general rule I think it would be good to include a caniuse type visual at the start of this kind of video.

  • @TusharShukladevx
    @TusharShukladevx 2 ปีที่แล้ว

    The 'Wowwwww 🤯' moment th-cam.com/video/cs37yx73b1o/w-d-xo.html

  • @valeriousmonk654
    @valeriousmonk654 2 ปีที่แล้ว

    WHATTTT???

  • @slaandf
    @slaandf 2 ปีที่แล้ว

    Alabama html

  • @diligencehumility6971
    @diligencehumility6971 2 ปีที่แล้ว

    Css is the most outdated and patched up thing

  • @BossPetta
    @BossPetta 2 ปีที่แล้ว

    🤯