有没有办法pre
通过 CSS 模拟元素的显示?
例如,我可以使用 CSS 规则保持这个 div 中的空白完整吗?
<div class="preformatted">
Please procure the following items:
- Soup
- Jam
- Hyphens
- Cantaloupe
</div>
有没有办法pre
通过 CSS 模拟元素的显示?
例如,我可以使用 CSS 规则保持这个 div 中的空白完整吗?
<div class="preformatted">
Please procure the following items:
- Soup
- Jam
- Hyphens
- Cantaloupe
</div>
用于white-space: pre
保留pre
元素中的空白预格式化。更进一步,还要添加font-family: monospace
,因为pre
默认情况下元素通常设置为等宽字体(例如用于代码块)。
.preformatted {
font-family: monospace;
white-space: pre;
}
<div class="preformatted">
Please procure the following items:
- Soup
- Jam
- Hyphens
- Cantaloupe
</div>
.preformatted {
white-space: pre-wrap;
}
我认为“预包装”更好。它可以帮助排长队。
为了让<pre>
你可以使用;
div.preformatted{ white-space: pre ; display: block; }