火狐长文字换行

IE下换行很简单

.table1 td{
    word-break: break-all;
    word-wrap: break-word;
}

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:
normal  Default. Allows line breaking within words.
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.
可是火狐没让你那么轻易,在没有设定宽度的情况下是无法换行的,所以你得设个宽给它,很郁闷,碰到做成控件的表格的时候麻烦啊,在插入表格的内容前后用个

content

在给tdWrap一个width的属性。也试过用js计算宽度,再把样式写上去,这个可能比较适合不确定宽的情况,呵呵,笨,不知道又没更好的(以上仅针对个人所遇到的情况,且针对表格里的内容)。
js计算宽度

        //firefox超长字符串处理,文字在有ID的div,且有以上样式,如果是class,可以遍历
        function firefoxLongString(elementID,width) {
            if (navigator.userAgent.indexOf("Firefox") > 0) {
                var w =width;
                document.getElementById(elementID).style.width = w + "px";
            }
        }

扩展下,不换行

.nowrap{
      white-space:nowrap;
}

所有浏览器都支持 white-space 属性,不过任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 “inherit”。

火狐长文字换行”有2 条评论

  1. 高血压饮食说:

    确实是不错~~~~~~~

    [2010年08月2日 21:28] 回复
  2. 丕子说:

    不错

    [2010年07月11日 20:53] 回复

评论一下