pre width属性指定每行的最大字符数。只有Firefox支持版本1.0到29.0的width属性。
在线示例
预格式化的文本,宽度为40个字符:
<!DOCTYPE html>
<html>
<head>
<title>HTML:<width> name 属性 - 大卫编程网(div.cn)</title>
</head>
<body>
<p>正常 pre:</p>
<pre>
Text in a pre element is displayed in a fixed-width
font, and it preserves both spaces and
line breaks
</pre>
<p>定义具体宽度的Pre:</p>
<pre width="40">
Text in a pre element is displayed in a fixed-width
font, and it preserves both spaces and
line breaks
</pre>
</body>
</html>
测试看看 ‹/›浏览器兼容性
IEFirefoxOperaChromeSafari
Firefox支持版本1.0到29.0的width属性。
定义和用法
HTML5 不支持 <pre> width 属性。请使用 CSS 代替。
在 HTML 4.01 中,<pre> 的 width 属性 已废弃。
width 属性指定每行的最大字符数。
兼容性注释
在 HTML 4.01 中,<pre> 的 width 属性已废弃。请使用 CSS 代替。
CSS 语法:<div style="width:200px;overflow:auto"><pre>Some text</pre></div>
在我们的 CSS 教程中,您可以找到更多有关 width 属性 的细节。
提示:如果文本的宽度超过周围元素的宽度,overflow 属性会添加一个滚动条。
语法
<pre width="number">
属性值
值 | 描述 |
---|---|
number | 设置以字符数为单位的宽度。 |
展开全部