Text implementation wrapping in pre label

Source: Internet
Author: User
Text that is surrounded in the pre element usually retains spaces and line breaks, but unfortunately, when you write code in the <pre> tag, if you do not manually wrap it, it will also hold it for you without Ming the line.

We all know that <pre> tags can define preformatted text, and a common application is to represent the source code of a computer. Text that is surrounded in the pre element usually retains spaces and line breaks, but unfortunately, when you write code in the <pre> tag, if you do not manually wrap it, it will also hold it for you without Ming the line.
At this point, you can use Overflow:auto (Display the scroll box when the code is outside the container boundary), but this method does not apply to all major browsers, and some browsers will directly truncate the excess content.


Because the site uses the source code is not a lot of places, before also not very concerned about this problem, not long ago there is an enthusiastic netizen in the QQ feedback on this issue, so in taking advantage of this change theme, looking for a solution to share.
pre{
white-space:pre-wrap;/*css-3*/
white-space:-moz-pre-wrap;/*mozilla,since1999*/
white-space:-pre-wrap;/*opera4-6*/
white-space:-o-pre-wrap;/*opera7*/
word-wrap:break-word;/*internetexplorer5.5+*/
}


The CSS scheme allows text to be wrapped in the pre label, and I tested it on all my browsers, all supported, Ie6,ie7,ie8,firefox,opera,safari and Chrome.

Only when you narrow the window to a width of less than 20 characters will the boundary be exceeded.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.