div realizes automatic line wrapping of long English letters using CSS (conversion)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:27:57
Original
1204 people have browsed it

原文地址: http://www.jz123.cn/text/0715896.html

自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换行的方法

最佳CSS定义换行代码

.wrap { table-layout:fixed; word-break: break-all; overflow:hidden; }
这里 overflow:hidden;或者 auto;
=================================================================


对于div,p等块级元素
正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义的宽度之后自动换行
html

正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义

css
#wrap{white-space:normal; width:200px; }

1.(IE浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word ;或者word-break:break-all;实现强制断行

#wrap{word-break:break-all; width:200px;}
或者
#wrap{word-wrap:break-word; width:200px;}

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

效果:可以实现换行

2.(Firefox浏览器)连续的英文字符和阿拉伯数字的断行,Firefox的所有版本的没有解决这个问题,我们只有让超出边界的字符隐藏或者,给容器添加滚动条


#wrap{word-break:break-all; width:200px; overflow:auto;}

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

Effect: The container is normal and the content is hidden

For table

1. (IE browser) use table-layout:fixed; to force the width of the table and hide the excess content





abcdefghigklmnopqrstuvwxyz1234567890sssssssssssss

Effect: hide excess content

2. (IE browser) use table-layout:fixed; to force the width of the table, The inner td,th uses word-break: break-all; or word-wrap: break-word; line break






abcdefghigklmnopqrstuvwxyz 1234567890
abcdefghigklmnopqrstuvwxyz 1234567890

Effect: Line breaks are possible

3. (IE browser) Nest div, p, etc. in td, th using the above mentioned div, p line wrapping method

4. (Firefox browser) use table- layout:fixed; enforces the width of the table. The inner td and th use word-break: break-all; or word-wrap: break-word; to wrap the line, use overflow:hidden; to hide the excess content. Overflow:auto; cannot be used here. Function






abcdefghigklmnopqrstuvwxyz1234567890

Effect: Hide more than content

5. (Firefox browser) in td, Nested divs, p, etc. in th use the method mentioned above to deal with Firefox
run the code box
Finally, the chance of this phenomenon occurring is very small, but netizens’ pranks cannot be ruled out.

The following is the effect of the mentioned example


< html  xmlns ="" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
< title > 字符换行
< style  type ="text/css" >
table,td,th,div {}{ border:1px green solid;}
code {}{ font-family:"Courier New", Courier, monospace;}


< body >
< h1 >< code > div
< h1 >< code > All white-space:normal;
< div  style ="white-space:normal; width:200px;" > Wordwrap still occurs in a td element that has its WIDTH attribute set to a value smaller than the unwrapped content of the cell, even if the noWrap property is set to true. Therefore, the WIDTH attribute takes precedence over the noWrap property in this scenario

< h1 >< code > IE word-wrap : break-word ;
< div  style ="word-wrap : break-word ; width:200px;" > abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111
< h1 >< code > IE word-break:break-all;
< div  style ="word-break:break-all;width:200px;" > abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

< h1 >< code > Firefox/ word-break:break-all; overflow:auto;
< div  style ="word-break:break-all; width:200px; overflow:auto;" > abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111
< h1 >< code > table
< h1 >< code > table-layout:fixed;
< table  style ="table-layout:fixed"  width ="200" >
< tr >
< td > abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss


< h1 >< code > table-layout:fixed; word-break : break-all; word-wrap : break-word ;
< table  width ="200"  style ="table-layout:fixed;" >
< tr >
< td  width ="25%"  style ="word-break : break-all; " > abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss
< td  style ="word-wrap : break-word ;" > abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss


< h1 >< code > FF table-layout:fixed; overflow:hidden;
< table  style ="table-layout:fixed"  width ="200" >
< tr >
< td  width ="25%"  style ="word-break : break-all; overflow:hidden; " > abcdefghigklmnopqrstuvwxyz1234567890
< td  width ="75%"  style ="word-wrap : break-word; overflow:hidden; " > abcdefghigklmnopqrstuvwxyz1234567890




 

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