pre标签自动换行方案

December 3, 2006 Tags: ,

pre标签会原样保留HTML内容的格式,可是如果宽度过大会把页面撑坏,这时候需要自动换行来帮忙:

Wrapping the pre tag

Making preformated text wrap in CSS3, Mozilla, Opera and IEis the tip that let’s you use the pre tag to keep the formatting, without cursing yourself when some of the content is too long and doesn’t wrap:

/* Browser specific (not valid) styles to make preformatted text wrap /
pre {
white-space: pre-wrap; /
css-3 /
white-space: -moz-pre-wrap; /
Mozilla, since 1999 /
white-space: -pre-wrap; /
Opera 4-6 /
white-space: -o-pre-wrap; /
Opera 7 /
word-wrap: break-word;      /
Internet Explorer 5.5+ */
}

来源:Ajaxian » Wrapping the pre tag

4 Comments on “pre标签自动换行方案”

  1. coocboy at 2:25 am on December 31st, 2006

    不行.

  2. coocboy at 10:14 am on February 12th, 2007

    在IE及table tr td 下无效,在div下是可以的.

    有table下解决方案吗?

  3. ash at 7:04 am on February 14th, 2007

    to coocboy:给td的width设上值试试。我这是可以的(FF2,IE7)。

  4. coocboy at 2:11 am on February 25th, 2007

    有设置width=”100%”,也就是设置百分比是不会换行的,
    但固定宽度我又用不上,只能让程序屏蔽pre这个办法好点.

Leave a Reply