Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White space issue for the Pre element

Tags:

html

css

I am facing a really annoying issue with the HTML pre element. I have no idea why it's creating so much white spaces when I never actually did that. Inside my code editor, everything is properly indented, made sure that the HTML is 100% valid but whenever I test on my browser; the white spaces suddenly appear. To make things more understandable, here's an image of how the pre looks inside my console.

enter image description here

And here's the HTML / CSS code.

HTML

<pre>
    &#60;!DOCTYPE html&#62;
    &#60;html&#62;
    &#60;head&#62;
    &#60;title&#62;My website&#60;title&#62;
    &#60;/head&#62;
    &#60;body&#62;

    &#60;script type="text/javascript"&#62;
         alert("Hello world!");
    &#60;/script&#62;
    &#60;/body&#62;
    &#60;/html&#62;
</pre>

CSS

pre{
    overflow: auto;
    background: #ddd;
    padding-left: 10px;
    padding-bottom: 10px;
    padding-top: 10px;
    white-space: pre-wrap;
    white-space: -moz-pre-wrap;
    white-space: -o-pre-wrap;
    white-space: -ms-pre-wrap;
}

If it helps, I am also using ratchet in order to make it mobile ready. (Please note that removing the white-space did not help). Regards.

like image 858
Ray Joe Avatar asked Nov 19 '15 02:11

Ray Joe


People also ask

What is white space pre?

The white-space property specifies how white-space inside an element is handled.

What is white space issue?

Whitespace error can be caused by either an unsupported character or symbol being passed to the gateway, or a blank or white space being left in a field. Most commonly, the Whitespace error is caused by characters or symbols that are not supported by global XML code being passed to the gateway.

Is white space an element?

White space, also known as “negative space,” is empty space around the content and functional elements of a page.

How do I get rid of unwanted white space in CSS?

We can also remove white space by setting parent element font-size to 0 and child elements font-size to 17px .


1 Answers

Instead of:

white-space: pre-wrap

Use:

white-space: pre-line

DEMO

white-space

The white-space property is used to describe how whitespace inside the element is handled.

pre-wrap

Sequences of whitespace are preserved.

pre-line

Sequences of whitespace are collapsed.

like image 166
Michael Benjamin Avatar answered Nov 15 '22 03:11

Michael Benjamin