Home  >  Q&A  >  body text

Is there a CSS-only way to break words on specific non-whitespace characters?

If a word (e.g. THIS_PHRASE_HERE) overflows its inner div (fixed width), I want to split it with an underscore. I know I can use word-break:break-all to split a word on any character, but that seems a bit confusing, especially if there are 1 or 2 character orphans at the end. I'm sure I can do this with JS, but was wondering if there's a way to do it just in CSS, like word-break: "_".

P粉807397973P粉807397973425 days ago726

reply all(2)I'll reply

  • P粉663883862

    P粉6638838622023-09-11 18:45:34

    Apparently there is no way to do this using just CSS, the word-break property doesn't have that option.
    You can use the html tag <wbr> to add work break opportunities where the browser can choose to break a line.

    reply
    0
  • 华趣免费图床

    Okay, great

    华趣免费图床 · 2023-09-11 21:11:08
  • Cancelreply