html长字符串自动换行,HTML+CSS中控制长字符串的自动换行问题

在HTML+CSS中,长字符串的自动换行问题,总是造成意想不到的麻烦。下面是一些相关的总结。

针对于div、p等块级元素:

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

1

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

2

3

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

2.(IE浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word

;或者word-break:break-all;实现强制断行

1

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

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

2

3

wwwiteaocomwwwiteaocomwwwiteaocomiteao

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

1

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

overflow:auto;}

2

3

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

对于表格table:

1. (IE浏览器)使用 table-layout:fixed;强制table的宽度,多余内容隐藏

1

2

3

abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss

4

5

2.(IE浏览器)使用 table-layout:fixed;强制table的宽度,内层td,th采用word-break :

break-all;或者word-wrap : break-word ;换行

1

style="table-layout:fixed;">

2

3

style="word-break :

break-all; ">wwwiteaocomwwwiteaocomwwwiteaocomiteao

4

wwwiteaocomwwwiteaocomwwwiteaocomiteao

5

6

3. (IE浏览器)在td,th中嵌套div,p等采用上面提到的div,p的换行方法

4.(Firefox浏览器)使用

table-layout:fixed;强制table的宽度,内层td,th采用word-break :

break-all;或者word-wrap : break-word

;换行,使用overflow:hidden;隐藏超出内容,这里overflow:auto;无法起作用

1

style="table-layout:fixed" width="200">

2

3

style="word-break :

break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890

4

style="word-wrap :

break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890

5

6

5.(Firefox浏览器)

在td,th中嵌套div,p等采用上面提到的对付Firefox的方法运行代码框,最后,这种现象出现的几率很小,但是不能排除网友的恶搞。

01

/p>

html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

03

04

content="text/html;

charset=gb2312" />

05

字符换行

06

07

table,td,th,div {

border:1px green solid;}

08

code {

font-family:"Courier New", Courier, monospace;}

09

10

11

12

13

div

14

15

16

All

white-space:normal;

17

18

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

19

20

21

IE

\ word-wrap : break-word ;

22

23

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

24

25

IE

\ word-break:break-all;

26

27

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

28

29

Firefox/ word-break:break-all;

overflow:auto;

30

31

abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111

32

33

table

34

35

36

table-layout:fixed;

37

38

39

40

abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss

41

42

43

44

table-layout:fixed; word-break :

break-all; word-wrap : break-word

;

45

46

style="table-layout:fixed;">

47

48

style="word-break :

break-all; ">abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss

49

abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss

50

51

52

53

FF

\ table-layout:fixed;

overflow:hidden;

54

55

56

57

style="word-break :

break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890

58

style="word-wrap :

break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890

59

60

61

62

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值