A flexbox trick to improve text wrapping

196,380
0
Published 2024-05-09
Checkout iCodeThis πŸ‘‰ icodethis.com/?ref=kevin

πŸ”— Links
βœ… My finished version: icodethis.com/modes/design-to-code/52/submissions/…
βœ… ICodeThis: icodethis.com/?ref=kevin
βœ… I have a 4-hour long course that deep dives flexbox: flexboxsimplified.com/

Disclaimer: Some of the links above might be affiliate links, which means that I'll receive a commission in case you like and decide to purchase the product or service. This comes at no extra cost for you, and helps support my channel 😊

⌚ Timestamps
00:00 - Introduction
00:45 - Why flex-grow or flex: 1 don't work
01:30 - flex-wrap doesn't solve the issue either
02:00 - min-width to the rescue
04:05 - more about icodethis

#css

--

Come hang out with other dev's in my Discord Community
πŸ’¬ discord.gg/nTYCvrK

Keep up to date with everything I'm up to
βœ‰ www.kevinpowell.co/newsletter

Come hang out with me live every Monday on Twitch!
πŸ“Ί www.twitch.tv/kevinpowellcss

---

Help support my channel
πŸ‘¨β€πŸŽ“ Get a course: www.kevinpowell.co/courses
πŸ‘• Buy a shirt: teespring.com/stores/making-t...
πŸ’– Support me on Patreon: www.patreon.com/kevinpowell

---

My editor: VS Code - code.visualstudio.com/

---

I'm on some other places on the internet too!

If you'd like a behind the scenes and previews of what's coming up on my YouTube channel, make sure to follow me on Instagram and Twitter.

Twitter: twitter.com/KevinJPowell
Codepen: codepen.io/kevinpowell/
Github: github.com/kevin-powell

---

And whatever you do, don't forget to keep on making your corner of the internet just a little bit more

All Comments (21)
  • @KevinPowell
    Quick note: I mispoke when I said flex: 1; will make it a flex-shrink: 0. It makes it flex-grow: 1; flex-shrink: 1; and flex-basis: 0; You'd almost never notice the difference as long as the flex-basis is 0, but still, I did make a mistake there, sorry about that!
  • @stairjoke
    I’ve been writing CSS for like 20 years and I feel like I know nothing.
  • @KB04
    Had the same problem, literally never thought of using fit-content on min/max width.
  • @pascalmaranus
    This is brilliant! Coincidentally, I had to make a small change to an older website today. And I noticed they have a similar issue with two buttons, because the client's changed the text on the buttons. It's bothered me for years at this point. I'm applying this there right away!
  • @Sagan1995
    Neat! You can also achieve the same results by adding "white-space: nowrap" to the buttons as well.
  • @adamrmoss
    I’m just grateful when the text isn’t trunc…
  • @artneo7
    The "min-width: fit-content;" declaration helped me out on a project, really cool tip when working with the flex layout! Thanks! πŸ™ŒπŸΌ
  • @sourabhgupta3811
    You just saved developers so much time with your solution to this common issue!
  • @tonydrake462
    thanks - after 40 years dev avoiding CSS, loving finally embracing it, you have added some cool stuff to my toolbox. thanks again.
  • @Feedback406
    The best css channel on YouTube and it’s not even close. Been watching for years Thank you!!!
  • @larrybahr489
    I love that this solution does not need media queries! Great video as always
  • @cwirus99
    That's the stuff! A simple, elegant solution to a common problem. Love it!
  • @venomus9286
    I fixed this with white-space: preline; but wasnt a fan how it ended in the end. This solution seems much better. Preline would just force the text not to break, but also had to add prettier ignore so it doesnt break the line. Takes a bit more setup. Thanks a lot Kevin for this solution, much appreciated :D
  • @DeffQ
    Someone mentioned you in different video and I'm so happy I discovered your channel. Useful stuff.
  • @iamtharunraj
    I have had this issue for so long and never knew how to fix them. Thank you so much, Kevin!
  • I honestly love short contents like these. I had this same issue and your solution was straightforward! I don't have time to watch a 30 minute or 12 hour video and then try to find which chapter and minute is the content I'm looking for. Thanks!
  • @FlorinPop
    New lesson for today! Thanks Kevin! 🀩
  • @JeremiahKellogg
    Nice! How glad am I this popped up as a recommended video right now. This solved a similar problem I was having and couldn't quite solve properly. This did exactly what I wanted. Thanks!
  • @lewybagz
    Your timing is insane i was literally just struggling with this on a landing page yesterday. The Goat