Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break a text line inside a <pre> tag

Tags:

html

jquery

css

pre

I have a screen shot of my code snippet in chrome:

enter image description here

and in firefox:

enter image description here

My question is, how do I make the same effect in firefox as it was in chrome? the code snippet part is inside a pre tag. thanks a lot for any help! :)

like image 376
Emkey Avatar asked Aug 10 '11 15:08

Emkey


People also ask

How do you force a line break in text?

To add spacing between lines or paragraphs of text in a cell, use a keyboard shortcut to add a new line. Click the location where you want to break the line. Press ALT+ENTER to insert the line break.

How do I wrap text in a pre tag?

HTML <pre> tag defines preformatted text. It is used to display code blocks since it preserves spaces and line breaks. If the line is large, then the <pre> tag won't wrap it by default. To wrap it, we need to use CSS.

How do you break text in HTML?

To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag.

How do you insert a line in HTML without br?

Here we will use ::after to style an HTML element to add a line break. In the code above, we use the pseudo-element ::after on each inline element (represented by the span) to add a carriage return (represented by the “\a”) after the span's line of text.

How do I show preformatted text in HTML?

The <pre> tag defines preformatted text. Text in a <pre> element is displayed in a fixed-width font, and the text preserves both spaces and line breaks. The text will be displayed exactly as written in the HTML source code.


1 Answers

Cross browser wrapping:

pre
{
    white-space: pre-wrap; /* CSS3 */
    white-space: -moz-pre-wrap; /* Mozilla, post millennium */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
}

JSFiddle

like image 175
Evan Mulawski Avatar answered Sep 29 '22 22:09

Evan Mulawski