White spaces not ignored in pre tag
I have read that the 'pre' tag will collapse all white spaces and ta开发者_如何学Pythonbs into one space, but it doesn't do so for me.
why is it so? is it depending on web browser or should I do something more?
From HTML 4.01 Specification
The PRE element tells visual user agents that the enclosed text is "preformatted". When handling preformatted text, visual user agents:
- May leave white space intact.
- May render text with a fixed-pitch font.
- May disable automatic word wrap.
- Must not disable bidirectional processing
PRE tags will leave white space as you have typed it. The purpose is just that. If you don't use a pre tag, standard HTML will collapse white space as you have written. Use PRE if you are interested in preserving white space, not collapsing it.
Here is an example in JSFiddle.
This will preserve white space:
<pre>
Spaces
and more
galore
</pre>
This will collapse white space:
<div>
All
together
now
</div>
The PRE tag will just keep you contents in the same format as you wrote it. it is used to keep your "preformatted" text the same way as you wrote it.
精彩评论