开发者

what is the use of a "PRE" tag in (X)HTML

开发者 https://www.devze.com 2022-12-21 20:20 出处:网络
what is the use of a \"PRE\" tag in (开发者_StackOverflow中文版X)HTMLIt\'s for displaying data/code/art where you want all your spaces and newlines to be displayed as is, and want your columns to line

what is the use of a "PRE" tag in (开发者_StackOverflow中文版X)HTML


It's for displaying data/code/art where you want all your spaces and newlines to be displayed as is, and want your columns to line up. So you can do stuff like this:

+-----+------------------+--------+------------+
| id  | session_key      | length | expires    |
+-----+------------------+--------+------------+
| 263 | SNoCeBJsZkUegA7F |  86400 | 1257401198 |
| 264 | UoVm3SZRmPHnac4V |  86400 | 1257405561 |
| 262 | bjkIOWBhI1qxcrWr |  86400 | 1257401189 |
+-----+------------------+--------+------------+

without "pre" or "code" or some such, this looks like this:

+-----+------------------+--------+------------+ | id | session_key | length | expires | +-----+------------------+--------+------------+ | 263 | SNoCeBJsZkUegA7F | 86400 | 1257401198 | | 264 | UoVm3SZRmPHnac4V | 86400 | 1257405561 | | 262 | bjkIOWBhI1qxcrWr | 86400 | 1257401189 | +-----+------------------+--------+------------+


It is used to demonstrate pre-formatted text, where new-line breaks are relevant. For instance, ascii art ;-) or program code. Well, for program code the CODE element is better.


The PRE element represents a character cell block of text and is suitable for text that has been formatted for a monospaced font.

The PRE tag may be used with the optional WIDTH attribute. The WIDTH attribute specifies the maximum number of characters for a line and allows the HTML user agent to select a suitable font and indentation.

Hypertext Markup Language - 2.0 specs from W3C


Have you ever looked an article posted in code project site ? If you didn't take a look at it this http://www.codeproject.com/KB/game/Hangman_game.aspx. From the article the yellow section or the one with collapse and expand code snippet are pre taged. It helps to preserve the data the way it is written or presented as it is without distorted.

0

精彩评论

暂无评论...
验证码 换一张
取 消