14. css-to wrap long strings in excess of width

Source: Internet
Author: User
Tags word wrap
I. Related information

When outputting a long string of PHP (the string is not wrapped) you want the string to wrap when the content is longer than the set length, otherwise the string with no newline symbol will exceed the width of the set, infinitely stretched page

In plain HTML code, automatic wrapping is automatically based on the width you set, even if you do not make any special declarations, such as

<divstyle="width: 100px;">测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
   
    div>

The above code will automatically wrap the output when the content width exceeds 100px.

But when you output a long string of PHP

<divstyle="width: 100px;">
    
     echo$long_content; ?>
    
     div>

$long_contentThe content width is far more than 100px, you can see the content output is not automatically wrapped, will be based on the width of the string infinitely stretched page, that is, how long it will stretch how long, the definition of the width of a dummy, obviously not what we expected

Ii. Description of the problem

When you output a long string, the content does not wrap, and the page is stretched infinitely.

Third, the solution

Use the following CSS definitions

<divstyle="width: 100px; word-break: break-all;word-wrap: break-word;">
    
     echo$long_content; ?>
    
     div>
    1. word-breakproperty specifies the method by which the word wrap is handled, and the value break-all indicates that line wrapping is allowed within the words.
    2. word-wrapproperty allows a long word or URL address to wrap to the next line, and the value break-word indicates a line break within a long word or URL address.

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the 14, css-let long string more than the width of the automatic line wrapping, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.