Home Backend Development PHP Tutorial 14. CSS - Automatically wrap a long string when it exceeds the width

14. CSS - Automatically wrap a long string when it exceeds the width

Jul 29, 2016 am 08:56 AM
break content word

1. 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>&lt;<span>div</span><span>style</span>=<span>"width: 100px;"</span>&gt;</span>
测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
<span>&lt;/<span>div</span>&gt;</span></code>
Copy after login

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>&lt;<span>div</span><span>style</span>=<span>"width: 100px;"</span>&gt;</span><span><span>&lt;?php</span><span>echo</span><span>$long_content</span>; <span>?&gt;</span></span><span>&lt;/<span>div</span>&gt;</span></code>
Copy after login

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>&lt;<span>div</span><span>style</span>=<span>"width: 100px; word-break: break-all;word-wrap: break-word;"</span>&gt;</span><span><span>&lt;?php</span><span>echo</span><span>$long_content</span>; <span>?&gt;</span></span><span>&lt;/<span>div</span>&gt;</span></code>
Copy after login

    word-break
  1. The attribute specifies the processing method of automatic line wrapping. The value break-all indicates that line breaks are allowed within words. . The
  2. word-wrap
  3. 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.
  4. ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i
').text(i)); }; $numbering.fadeIn(1700); }); }); The above has introduced 14. CSS - Automatically wrap a long string when it exceeds the width, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to cancel automatic word wrapping in word How to cancel automatic word wrapping in word Mar 19, 2024 pm 10:16 PM

How to cancel automatic word wrapping in word

Detailed explanation of how to display the ruler in Word and how to operate the ruler! Detailed explanation of how to display the ruler in Word and how to operate the ruler! Mar 20, 2024 am 10:46 AM

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

How to add handwritten signature to word document How to add handwritten signature to word document Mar 20, 2024 pm 08:56 PM

How to add handwritten signature to word document

How to set page margins for Word How to set page margins for Word Mar 19, 2024 pm 10:00 PM

How to set page margins for Word

How to draw a dotted line in word How to draw a dotted line in word Mar 19, 2024 pm 10:25 PM

How to draw a dotted line in word

Where is the shading setting in word? Where is the shading setting in word? Mar 20, 2024 am 08:16 AM

Where is the shading setting in word?

How to automatically sort word serial numbers How to automatically sort word serial numbers Mar 20, 2024 pm 09:20 PM

How to automatically sort word serial numbers

How to underline in word How to underline in word Mar 19, 2024 pm 10:49 PM

How to underline in word

See all articles