html的標籤用可定義預格式化的文本。

html的<pre></pre>標籤用可定義預格式化的文本。被包圍在 pre 元素中的文本通常會保留空格和換行符。而文本也會呈現爲等寬字體。

而爲了限制文本顯示的範圍,一般使用div+css設定自動換行或縮略等樣式。對於未知的文本格式,如果要求文本單行過長時換行顯示,並且保留原文本的空格和換行符,就可以通過div+pre標籤的組合,再分別設定各自的樣式來實現(pre標籤一般不適用width屬性)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST</title>
<style type="text/css">
div {
    width: 100px;
    white-space: normal;
}
 
pre {
    white-space: pre-wrap; /*css-3*/
    white-space: -moz-pre-wrap; /*Mozilla,since1999*/
    white-space: -pre-wrap; /*Opera4-6*/
    white-space: -o-pre-wrap; /*Opera7*/
    word-wrap: break-word; /*InternetExplorer5.5+*/
}
</style>
<body>
    <div>
        <pre>    文本文本文本文本文本文本文本文本文本文本文本
        文本
        文本
        文本
        </pre>
    </div>
</body>
</html>

 

<pre>css來源:http://www.3lian.com/edu/2011/03-08/4322.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章