天天看点

page-break-before Attribute

page-break-before Attribute | pageBreakBefore Property

Sets or retrieves a string indicating whether a page break occurs before the object.

Syntax

HTML { page-break-before : sBreak }
Scripting [ sBreak = ] object.style.pageBreakBefore

Possible Values

sBreak

String that specifies or receives one of the following values.

always

Always insert a page break before the object.

总是在对象前面分页

auto

Default. Neither force nor forbid a page break before the object.

默认。既不强制也不禁止在对象前面分页

avoid

Internet Explorer 8. Forbid a page break before the object, if possible.

在IE8中禁止在对象前面分页

empty string

Behaves the same as auto.

与auto属性相同

inherit

Internet Explorer 8. Inherit the value of the same property for the object's parent.

left

Currently behaves the same as always.

right

Currently behaves the same as always.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of auto. The Cascading Style Sheets (CSS) attribute is not inherited.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are not supported in IE8 mode. For more information, see About Dynamic Properties.

Remarks

This property applies when printing the document. This property does not apply to the BR or HR elements.

If there are conflicts between the value of this property and the pageBreakAfter property of the object previously displayed in the browser, the value that results in the largest number of page breaks is used.

Page breaks are not permitted inside positioned objects.

Examples

The following examples use the page-break-before attribute and the pageBreakBefore property to start printing on a new page.

This example uses the H3 element as a selector in an embedded style sheet to break the page before all H3 headings.

Copy Code

<html>

<head>

<style type="text/css">

h3 {

        page-break-before: always;

}

</style>

</head>

<body>

<p>

:

</p>

<h3>Start New Section on New Page</h3>

</body>

</html>

This example uses a button to turn off the page break before the object that has an ID value of oPrgrph. When the page is printed or previewed, a page break occurs before the first paragraph unless the user clicks the button.

Copy Code

<html>

<head>

<script type="text/javascript">

function offBreak()

{

    oPrgrph.style.pageBreakBefore="";

}

</script>

</head>

<body>

<button οnclick="offBreak()">Turn Off Break</button>

<p id="oPrgrph" style="page-break-before: always">

:

</p>

</body>

</html>