html word-break,HTML Style wordBreak用法及代码示例

DOM样式wordBreak属性用于设置或返回word-break属性。 word-break属性用于指定在行尾到达单词时如何中断单词。文本中的换行符可以出现在特定的wordBreak属性中。

用法:

它用于返回wordbreak属性:object.style.wordBreak

它用于设置wordBreak属性:object.style.wordBreak = "normal|break-all|keep-all|initial|

inherit"

属性值:

normal:此属性使用默认的换行规则。

break-all:它用于在任何字符处打断单词以防止溢出。

Keep-all:与正常值相同。

break-word:它用于在任意点处打断单词以防止溢出。

initial:它将属性设置为其默认值。

示例1:

p {

width:140px;

border:1px solid #000000;

}

#gfg {

word-break:normal;

}

GeeksforGeeks

DOM Style wordBreak Property

GeeksforGeeksGeeksGeeks.

A computer science portal for geeks .

Submit

function myGeeks() {

document.getElementById("gfg").style.wordBreak = "break-all";

}

在单击按钮之前:

22660faedd8524712e59a6c7a759155d.png

单击按钮后:

7c607d17a4d519edccab1e308068533f.png

示例2:

p {

width:140px;

border:1px solid #000000;

}

#gfg {

word-break:break-all;

}

GeeksforGeeks

DOM Style wordBreak Property

GeeksforGeeksGeeksGeeks.

A computer science portal for geeks .

Submit

function myGeeks() {

document.getElementById("gfg").style.wordBreak = "normal";

}

输出:

在单击按钮之前:

7c607d17a4d519edccab1e308068533f.png

单击按钮后:

22660faedd8524712e59a6c7a759155d.png

支持的浏览器:下面列出了DOM样式wordBreak属性支持的浏览器:

谷歌浏览器

IE浏览器

Firefox

Opera

Safari

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值