Pricing Blog

why this wrapping behavior?

  • ssssadsadasd-1365980210805084210

    ssssadsadasd

    3 months ago

    [here ](https://toddle.dev/projects/moccasin_palpatine_chief_rook/branches/start/components/test12?canvas-height=800&canvas-width=213.9&rightpanel=style) I have a list of spans and I want to wrap them, i.e. when the width is low I want the text to go to the next line. and I achieve this.
    but what makes me wonder is that if I changes the flex of the main div of the page from column to row the wrapping behavior is broken even though I do not know why this should influence the wrapping.
    anyone has any idea? thanks
    1365980212055113789-image.png
    1365980211044290580-image.png
  • kingdragxn-1365981387114676285

    Jay | DRAGXN

    3 months ago

    Why do a list of spans when you could merge them all into a single string?
  • 814597015002415184-@ssssadsadasd
    [here ](https://toddle.dev/projects/moccasin_palpatine_chief_rook/branches/start/components/test12?canvas-height=800&canvas-width=213.9&rightpanel=style) I have a list of spans and I want to wrap them, i.e. when the width is low I want the text to go to the next line. and I achieve this.
    but what makes me wonder is that if I changes the flex of the main div of the page from column to row the wrapping behavior is broken even though I do not know why this should influence the wrapping.
    anyone has any idea? thanks
    filip_dajkovic-1365986734763933707

    Filip Dajkovic

    3 months ago

    You can prevent that by adding width: 100%; or flex: 1; to this 2nd div
    1365986734453686333-CleanShot_2025-04-27_at_11.41.332x.png
  • kingdragxn-1365993002685956168

    Jay | DRAGXN

    3 months ago

    Ah I see it might be related to your other help questions. In that case you want to set either width (like @Filip Dajkovic said) or max-width to 100%.
    1365993002379776060-Screenshot_2025-04-27_at_6.05.43_AM.png
  • ssssadsadasd-1366025288902770779

    ssssadsadasd

    3 months ago

    thanks both
  • ssssadsadasd-1366034942311661660

    ssssadsadasd

    3 months ago

    1366034942383100015-image.png
  • lucasg-1366041509878829149

    Lucas G

    3 months ago

    1366041509811716118-image.png
  • The spans don't need to be flex containers
  • they just need to have a max-width of 100%
  • ssssadsadasd-1366044033712918621

    ssssadsadasd

    3 months ago

    @Lucas G yeah, thanks. just one last thing. suppose I have sth like "@elonmusk is the ceo of x and jeff bezos is the ceo of amazon", so a tag at the beginning and a long text after (so two elements in the list). this breaks immediately after @elonmusk. I would want the long text to continue immediately after and then brake at the end of the line
    1366044033671233596-image.png
  • filip_dajkovic-1366054891188916338

    Filip Dajkovic

    3 months ago

    I'm not sure if this is the best/only way to achieve that but you could have every word as a span by splitting the sentence on every space (" "). And than you can setup the class and logic for your tags by looking if the word starts with "@". Not sure if it's best practice and if there would be any issues with it.
  • ssssadsadasd-1366065499443691754

    ssssadsadasd

    3 months ago

    @Filip Dajkovic this is what I implemented actually. thing is that when there are two spans like this:
    @elonmusk
    is the ceo of x and jeff bezos is the ceo of amazon

    it immediately breaks after the second span, as a sentence, exceeds the scren size. I want the second span to break word by word
  • lucasg-1366081290243145859

    Lucas G

    3 months ago

    How big of a text would you be doing this to?
  • You’d be creating a massive DOM tree if you split everything word for word
  • ssssadsadasd-1366082160855093288

    ssssadsadasd

    3 months ago

    @Lucas G
    it is not split word by word but by tag. so
    @elonmusk is the ceo of x - two spans ("@elonmusk", "is the ceo of x")
    @elonmusk is the ceo of @x - three spans ("@elonmusk", "is the ceo of", "@x")
  • lucasg-1366089391843442788

    Lucas G

    3 months ago

    Ok took a closer look at it and spltting text is not a good solution, clearly
  • The issue is spreaking things into their own spans
  • lucasg-1366091178843570266

    Lucas G

    3 months ago

    Updated the original post
  • filip_dajkovic-1366091189429997690

    Filip Dajkovic

    3 months ago

    @ssssadsadasd he's right, you should keep things as they are now, just change the div wrapping spans and spans too to display: inline and you'll get them to wrap properly😁
    1366091188851179640-CleanShot_2025-04-27_at_18.37.322x.png
  • lucasg-1366091448768004127

    Lucas G

    3 months ago

    On a sidenote, there are too many divs being used 😂
  • lucasg-1366091741299740764

    Lucas G

    3 months ago

    This does still create a bunch of span tags unfortunately. I think I would go with a JS approach
  • But it works though
  • ssssadsadasd-1366122015253205094

    ssssadsadasd

    3 months ago

    @Filip Dajkovic hmm I changed to inline but it is not changing for me..
    1366122015022645298-image.png
  • lucasg-1366123154778488964

    Lucas G

    3 months ago

    Looking at his screenshot, he set both the div and span to inline
  • ssssadsadasd-1366123245438369875

    ssssadsadasd

    3 months ago

    @Lucas G ah yeah, thanks
  • lucasg-1366123327986339963

    Lucas G

    3 months ago

    I’d get rid of the additional divs though but I know this is just for demo purposes
  • ssssadsadasd-1366123480969515110

    ssssadsadasd

    3 months ago

    @Lucas G yeah the divs are just for demo purposues to show different texts. sorry for the confusion
  • lucasg-1366124100224942151

    Lucas G

    3 months ago

    No no it’s alright. I’m just a “use the least amount of divs as possible” person lol
  • lucasg-1366124403426857040

    Lucas G

    3 months ago

    Generally speaking, we wanna keep the DOM clean but this isn’t prod it’s fine 😬