white-space
Description
white-space
declares how whitespace is handled during layout.
Item | Value |
---|---|
Initial value | normal |
Inherited | No. |
Version | CSS1 |
JavaScript syntax | object.style.whiteSpace="pre" |
Applies to | All elements. |
Syntax and Property Values
white-space: normal | pre | nowrap | pre-wrap | pre-line | inherit
The property values are listed in the following table.
Value | Description |
---|---|
normal | Default value. Collapse to a single whitespace. Wrap text if necessary. |
nowrap | Collapse to a single whitespace. Text not wrap to the next line. |
pre | Preserve whitespace. Act as <pre> tag |
pre-line | Collapse to a single whitespace. Wrap text on line breaks |
pre-wrap | Preserve whitespace. Wrap text on line breaks |
inherit | Inherit white-space property from parent element |
Example
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
p {<!-- www .j ava 2 s.co m-->
white-space: pre;
margin: 0;
}
</style>
</head>
<body>
<div>
<p> this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test.
this is a test. </p>
</div>
</body>
</html>
The code above generates the following result.