订阅本栏目 RSS您所在的位置: 深山工作室 > DIV+CSS > 正文

CSS中word-wrap属性同word-break属性的两者在中英文混排时的区别

天极网 2007/12/12 21:25:59 深山行者 字体: 浏览 10523
本文列举了兼容 IE 和 FF 的换行 CSS 推荐样式,详细介绍了word-wrapword-break的区别。

  兼容 IE 和 FF 的换行 CSS 推荐样式

  最好的方式是

以下是引用片段:
  word-wrap:break-word; overflow:hidden;

  而不是

以下是引用片段:
  word-wrap:break-word; word-break:break-all;

  也不是

以下是引用片段:
  word-wrap:break-word; overflow:auto;

  在 IE 下没有任何问题,在 FF 下,长串英文会被遮住超出的内容。

  word-wrap同word-break的区别

  word-wrap:

  normal  Default. Content exceeds the boundaries of its container.

  break-word Content wraps to next line, and a word-break occurs when necessary. 必要时会触发word-break。

  word-break:

  normal  Default. Allows line breaking within words. 好像是只对Asian text起作用。

  break-all Behaves the same as normal for Asian text, yet allows the line to break arbitrarily for non-Asian text. This value is suited to Asian text that contains some excerpts of non-Asian text.

  keep-all Does not allow word breaking for Chinese, Japanese, and Korean. Functions the same way as normal for all non-Asian languages. This value is optimized for text that includes small amounts of Chinese, Japanese, or Korean.

  总结如下:

  word-wrap是控制换行的。

  使用break-word时,是将强制换行。中文没有任何问题,英文语句也没问题。但是对于长串的英文,就不起作用。

  break-word是控制是否断词的。

  normal是默认情况,英文单词不被拆开。

  break-all,是断开单词。在单词到边界时,下个字母自动到下一行。主要解决了长串英文的问题。

  keep-all,是指Chinese, Japanese, and Korean不断词。即只用此时,不用word-wrap,中文就不会换行了。(英文语句正常。)

  ie下:

  使用word-wrap:break-word;所有的都正常。

  ff下:

  如这2个都不用的话,中文不会出任何问题。英文语句也不会出问题。但是,长串英文会出问题。

  为了解决长串英文,一般用word-wrap:break-word;word-break:break-all;。但是,此方式会导致,普通的英文语句中的单词会被断开(ie下也是)。

  目前主要的问题存在于 长串英文 和 英文单词被断开。其实长串英文就是一个比较长的单词而已。

  即英文单词应不应该被断开那?那问题很明显了,显然不应该被断开了。

  对于长串英文,就是恶意的东西,自然不用去管了。但是,也要想些办法,不让它把容器撑大。

  用:overflow:auto; ie下,长串会自动折行。ff下,长串会被遮盖。

  所以,综上,最好的方式是word-wrap:break-word;overflow:hidden;而不是word-wrap:break-word;word-break:break-all;。

  word-wrap:break-word;overflow:auto;在ie下没有任何问题。在ff下,长串会被遮住部分内容。

  另,测试代码如下:

  1.htm

  <style>

  .c1{ width:300px;  border:1px solid red}

  .c2{ width:300px;word-wrap:break-word;  border:1px solid yellow}

  .c3{ width:300px;word-wrap:break-word;word-break:break-all;  border:1px solid green}

  .c4{ width:300px;word-wrap:break-word;word-break:keep-all; border:1px solid blue}

  .c5{ width:300px;word-break:break-all;  border:1px solid black}

  .c6{ width:300px;word-break:keep-all;  border:1px solid red}

  .c7{ width:300px;word-wrap:break-word;overflow:auto;  border:1px solid yellow}

  </style>

  .c1{ width:300px;  border:1px solid red}

  <div class="c1">asdasd

      </div>

  <div class=c1>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c1>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c1>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c2{ width:300px;word-wrap:break-word; border:1px solid yellow}

  <div class="c2">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c2>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c2>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c2>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c3{ width:300px;word-wrap:break-word;word-break:break-all;  border:1px solid green}

  <div class="c3">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c3>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c3>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c3>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c4{ width:300px;word-wrap:break-word;word-break:keep-all; border:1px solid blue}

  <div class="c4">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c4>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c4>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c4>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c5{ width:300px;word-break:break-all;  border:1px solid black}

  <div class="c5">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c5>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c5>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c5>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c6{ width:300px;word-break:keep-all;  border:1px solid red}

  <div class="c6">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c6>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c6>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c6>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

  <br>

  .c7{ width:300px;word-wrap:break-word;overflow:auto;  border:1px solid yellow}

  <div class="c7">

  safjaskflasjfklsajfklasjflksajflksjflkasjfksafj

  </div>

  <div class=c7>

  This is all English. This is all English. This is all English.

  </div>

  <div class=c7>

  全是中文的情况。全是中文的情况。全是中文的情况。

  </div>

  <div class=c7>

  中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.

  </div>

相关阅读
详解VBScript里的对象 正则表达式功能介绍
利用css中的scale()实现放大缩小效果
做在线客服时,聊天窗口的div滚动条始终在底部
在服务器上新建网站,在服务器用域名能访问,但是外网访问不了的解决办法
成都中国青年旅行社开心旅游网
襄阳康辉国际旅行社
超过服务期限如何办?
诸城阳光旅行社
共有0条关于《CSS中word-wrap属性同word-break属性的两者在中英文混排时的区别》的评论
发表评论
正在加载评论......
返回顶部发表评论
呢 称:
表 情:
内 容:
评论内容:不能超过 1000 字,需审核,请自觉遵守互联网相关政策法规。
验证码: 验证码 
网友评论声明,请自觉遵守互联网相关政策法规。

您发布的评论即表示同意遵守以下条款:
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家、社会、集体和公民的合法权益;
二、不得发布国家法律、法规明令禁止的内容;互相尊重,对自己在本站的言论和行为负责;
三、本站对您所发布内容拥有处置权。

更多信息>>栏目类别选择
百度小程序开发
微信小程序开发
微信公众号开发
uni-app
asp函数库
ASP
DIV+CSS
HTML
python
更多>>同类信息
jquery设置或获取修改classname
利用css3.0写出一个音乐播放的唱片碟盘的效果
利用css中的scale()实现放大缩小效果
利用background-color:#000000a8在背景颜色16进制代码之后加字母加上数字让背景色透明
css背景使用base64编码或者将base64编码放在img图片标签中
利用css3中的-webkit-font-smoothing把网页文字的毛边去掉
更多>>最新添加文章
在Android、iOS、Windows、MacOS中微信小程序的文件存放路径
python通过代码修改pip下载源让下载库飞起
python里面requests.post返回的res.text还有其它的吗
aliyun阿里云续费域名优惠口令(注册、续费都可以使用)
windows7环境下安装配置jdk
python对微信操作要用到这两个库wxpy与itchat
ASP中Utf-8与Gb2312编码转换乱码问题的解决方法页面编码声明
DW设置之后更好用 DreamweaverCS编辑GB2312与UTF-8文件在代码视图中点击鼠标错位问题的解决办法
更多>>随机抽取信息
div中的图片链接居中的问题
asp自定义格式化日期函数
总结一下with open()和open()的区别与使用方法
旅行社线路主题默认模板5
FLASH中加入LOADING的最简便方法
深山网吧留言板系统v4.0