


14. CSS - Automatically wrap a long string when it exceeds the width
Jul 29, 2016 am 08:56 AM1. Related information
When outputting a long string in PHP (the string has no line breaks), it is hoped that the string can automatically wrap when the content exceeds the set length, otherwise the string without line breaks will Exceeding the set width, the page will be stretched infinitely
In pure HTML code, even without any special declaration, it will automatically wrap according to the set width, for example
<code><span><<span>div</span><span>style</span>=<span>"width: 100px;"</span>></span> 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试 <span></<span>div</span>></span></code>
The above code will when the content width exceeds 100px Will automatically wrap the output
But when outputting a long string of php
<code><span><<span>div</span><span>style</span>=<span>"width: 100px;"</span>></span><span><span><?php</span><span>echo</span><span>$long_content</span>; <span>?></span></span><span></<span>div</span>></span></code>
The content width of $long_content
is far more than 100px, you can see that the content output will not automatically wrap the line, it will be based on the string The width of the page is infinitely stretched, that is, it will be stretched as long as it is. The defined width is imaginary, which is obviously not what we expect. 2. Problem description
When a long string is output, the content will not Automatic line wrapping will stretch the page infinitely
3. Solution
Use the following css definition
<code><span><<span>div</span><span>style</span>=<span>"width: 100px; word-break: break-all;word-wrap: break-word;"</span>></span><span><span><?php</span><span>echo</span><span>$long_content</span>; <span>?></span></span><span></<span>div</span>></span></code>
- word-break
- The attribute specifies the processing method of automatic line wrapping. The value
break-all
indicates that line breaks are allowed within words. . The word-wrap - attribute allows long words or URL addresses to wrap to the next line. The value
break-word
means wrapping inside long words or URL addresses. ').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to cancel automatic word wrapping in word

Detailed explanation of how to display the ruler in Word and how to operate the ruler!

How to add handwritten signature to word document

Where is the shading setting in word?

How to automatically sort word serial numbers
