个人认为pre还是用overflow:auto;比较好,可以保持代码的完整。但你如果一定要换行就用下列代码吧。IE5.0以下不行,不过IE5.0也没有什么人用了!

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 */
}

pre{
#word-break: break-all;      /* Internet Explorer 7.0+ */
#word-wrap: break-word;      /* Internet Explorer 7.0+ */
_word-break: break-all;      /* Internet Explorer 6.0- */
_word-wrap: break-word;      /* Internet Explorer 6.0- */
}

One Comment

  • Leland

    很好,受教了,正发愁FIREFOX升级到3.5后怎么pre换行出了问题

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *