Home > Web Front-end > CSS Tutorial > How to implement automatic line wrapping in firefox css_Experience exchange

How to implement automatic line wrapping in firefox css_Experience exchange

WBOY
Release: 2016-05-16 12:05:08
Original
2091 people have browsed it

Use IE directly:
word-break:break-all; /*Allow line breaks within words*/
word-wrap:break-word; /*The content will wrap within the boundary*/
/*Required Note that the default is: */
word-wrap:normal /*Allow content to open the specified window boundary*/
However, Firefox does not have a good implementation method. A compromise solution is to use scroll bars, but A method of using js to determine line breaks has also been proposed on the Internet, which is excerpted here (reprinted from the Internet, hereby explained). JavaScript copy code
<script>     <BR>function toBreakWord(intLen, id){     <BR>    var obj=document.getElementById(id);     <BR>    var strContent=obj.innerHTML;      <BR>    var strTemp="";     <BR>    while(strContent.length>intLen){     <BR>        strTemp+=strContent.substr(0,intLen)+"<br>";      <BR>        strContent=strContent.substr(intLen,strContent.length);      <BR>    }     <BR>    strTemp+= strContent;     <BR>    obj.innerHTML=strTemp;     <BR>}     <BR></script>
Note: The above script is placed in front of .

Single call on the same page:

Here This is the content to which line breaks should be applied
<script>toBreakWord(60, "content");</script> 
Multiple calls on the same page:

This is the content to which line breaks should be applied
<script>toBreakWord(60,"content");</script> 
Here is the content to apply line breaks
<script>toBreakWord(60,"content2");</script>

Note: Write the application JS behind , where 60 indicates how many characters should be displayed in one line. Pay attention to the corresponding changes in the ID when multiple calls are made. The same ID name cannot be used. After applying the above method, IE will also wrap according to the set number of characters. However, IE supports automatic line wrapping, so just judge whether it is IE. If not, IE should not output the above XML/HTML copy code
<script>toBreakWord(60, "content");</script>
This JS, if not, output it. The code has not been tested, I only read the ideas, debug it yourself if necessary! Leave me a message if there are any errors.
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template