<pre>
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015å¹´7æâ©.
HTML <pre> å ç´ è¡¨ç¤ºé¢å®ä¹æ ¼å¼ææ¬ãå¨è¯¥å ç´ ä¸çææ¬é常æç §åæä»¶ä¸çç¼æï¼ä»¥ç宽åä½çå½¢å¼å±ç°åºæ¥ï¼ææ¬ä¸ç空ç½ç¬¦ï¼æ¯å¦ç©ºæ ¼åæ¢è¡ç¬¦ï¼é½ä¼æ¾ç¤ºåºæ¥ã(ç´§è·å¨ <pre> å¼å§æ ç¾åçæ¢è¡ç¬¦ä¹ä¼è¢«çç¥)
å°è¯ä¸ä¸
<pre>
L TE
A A
C V
R A
DOU
LOU
REUSE
QUE TU
PORTES
ET QUI T'
ORNE O CI
VILISÃ
OTE- TU VEUX
LA BIEN
SI RESPI
RER - Apollinaire
</pre>
pre {
font-size: 0.7rem;
margin: 0;
}
夿³¨ï¼ä½ éè¦å°è¯¥å ç´ éç '<' å符转ä¹ä¸º '<' 以ä¿è¯ä»£ç éçå ³é代ç ä¸è¢«æµè§å¨è§£é为æ ç¾ã
| å å®¹ç±»å« | æµå 容 ( flow content) , å¯è§¦ç¥çå 容 (palpable content). |
|---|---|
| å 许ç å 容 | Phrasing content. |
| æ ç¾çç¥ | ä¸å 许ï¼å¼å§æ ç¾åç»ææ ç¾é½ä¸è½çç¥ã |
| å 许ç ç¶å ç´ | ä»»ä½å¯ä»¥æ¥åæµå 容 ( flow content) çå ç´ |
| å 许ç ARIA è§è² | ä»»ä½ |
| DOM æ¥å£ | HTMLPreElement |
屿§
è¿ä¸ªå ç´ åªå ·æå ¨å±å±æ§ã
colséæ å å·²å¼ç¨-
å®ä¹æ¯è¡çæå¤§å符æ°ãè¿æ¯ä¸ä¸ªéæ åç屿§ï¼ä½ç¨ä¸
widthç¸åãè¦å®ç°è¿æ ·çææï¼åºè¯¥ä½¿ç¨ CSSã widthå·²å¼ç¨-
å 嫿¯è¡çæå¤§å符æ°ãè½ç¶å¨ææ¯ä¸ä»è¢«å®ç°ï¼ä½è¿ä¸ªå±æ§æ²¡æè§è§ææãè¦å®ç°è¿æ ·çææï¼åºè¯¥ä½¿ç¨ CSSã
wrapéæ å-
æç¤ºæº¢åºææ ·åçãå¨ç°ä»£æµè§å¨ä¸ï¼è¿ä¸ªæç¤ºä¼è¢«å¿½ç¥ï¼ä¸è¢«æ²¡æè§è§ææãè¦å®ç°è¿æ ·çææï¼åºè¯¥ä½¿ç¨ CSSã
示ä¾
>HTML
<p>Using CSS to change the font color is easy.</p>
<pre>
body {
color: red;
}
</pre>
ç»æ
æ éç¢
It is important to provide an alternate description for any images or diagrams created using preformatted text. The alternate description should clearly and concisely describe the image or diagram's content.
People experiencing low vision conditions and browsing with the aid of assistive technology such as a screen reader may not understand what the preformatted text characters are representing when they are read out in sequence.
A combination of the <figure> and <figcaption> elements, supplemented by a combination of an id and the ARIA role and aria-labelledby attributes allow the preformatted text to be announced as an image, with the figcaption serving as the image's alternate description.
示ä¾
<figure role="img" aria-labelledby="cow-caption">
<pre>
___________________________
< I'm an expert in my field. >
---------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
</pre>
<figcaption id="cow-caption">
A cow saying, "I'm an expert in my field." The cow is illustrated using preformatted text characters.
</figcaption>
</figure>
è§è
| Specification |
|---|
| HTML > # the-pre-element > |
æµè§å¨å ¼å®¹æ§
åè§
- CSS:
white-space,word-break