How to break word after special character like Hyphens (-)

后端 未结 11 1988
南方客
南方客 2020-12-04 17:31

Given a relatively simple CSS:

相关标签:
11条回答
  • 2020-12-04 17:57

    Instead of - you can use ‐ or \u2010.

    Also, make sure the hyphens css property was not set to none (The default value is manual).

    <wbr> is not supported by Internet Explorer.

    0 讨论(0)
  • 2020-12-04 17:58

    You can also use :

    word-break:break-all;
    

    ex.

    <div style='width:10px'>ababababababbabaabababababababbabababa</div>
    

    output:

    abababababa
    ababababbba
    abbabbababa
    ababb
    

    word-break is break all the word or line even if no-space in sentence that not feets in provided width or height. nut for that you must be provide a width or height.

    0 讨论(0)
  • 2020-12-04 18:10

    Your example works as expected in Google Chrome, Safari (Windows), and IE8. The text breaks out of the 150px box in Firefox 3 and Opera 9.5.

    Additionally &shy; won't work for your example, as it will either:

    • work when word-breaking but when not word-breaking not display any hyphens, or

    • work when not word-breaking but display two hyphens when word-breaking since it adds a hyphen on a break.

    0 讨论(0)
  • 2020-12-04 18:13

    In all modern browsers* (and in some older browsers, too), the <wbr> element is the perfect tool for providing the opportunity to break long words at specific points.

    To quote from that link:

    The Word Break Opportunity (<wbr>) HTML element represents a position within text where the browser may optionally break a line, though its line-breaking rules would not otherwise create a break at that location.

    Here's how it could be used to in the OP's example (or see it in action at JSFiddle):

    <div style="width: 150px;">
      12333-<wbr>2333-<wbr>233-<wbr>23339392-<wbr>332332323
    </div>
    

    *I've tested it in IE9, IE10, and the latest versions of Chrome, Firefox, and Opera, and Safari.

    div {
      width: 150px;
    }
    <div>
      12333-<wbr>2333-<wbr>233-<wbr>23339392-<wbr>332332323
    </div>

    0 讨论(0)
  • 2020-12-04 18:14

    Hope this may help

    use <br>(break) tag where you want to break the line.

    0 讨论(0)
提交回复
热议问题