HTML DOM Style whiteSpace property
Definition and Usage
whiteSpace property sets or returns how to handle text tabs, line breaks and spaces.
grammar
Setting whiteSpace properties:
Object.style.whiteSpace="normal|nowrap|pre|inherit"
Back whiteSpace properties:
Object.style.whiteSpace
值 | 描述 |
---|---|
normal | 默认。自动忽略空格符和换行符。 |
nowrap | 忽略空格符,但是不允许换行符。 |
pre | 换行符和其他空格符会被保留。 |
inherit | whiteSpace 属性的值从父元素继承。 |
Browser Support
All major browsers support whiteSpace property.
Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".
Examples
Examples
Retain text line breaks and whitespace:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
. Document.getElementById ( "div1") style.whiteSpace = "pre";
}
</ Script>
</ Head>
<Body>
<Div id = "div1">
This is some text. This is some text. This is some text. This is some text. This is some text.
</ Div>
<br>
<Button type = "button" onclick = "displayResult ()"> to retain line breaks and whitespace </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
. Document.getElementById ( "div1") style.whiteSpace = "pre";
}
</ Script>
</ Head>
<Body>
<Div id = "div1">
This is some text. This is some text. This is some text. This is some text. This is some text.
</ Div>
<br>
<Button type = "button" onclick = "displayResult ()"> to retain line breaks and whitespace </ button>
</ Body>
</ Html>
try it"
Style Objects