Style widowsProperty

Style 对象参考手册Style Object

Definition and Usage

The widows property sets or returns the minimum number of visible lines an element must have at the top of a page (for printing or print preview).

The widows property only affects block-level elements.

Tip:widows:5 means that at least 5 lines must be visible below a page break.

Tip:The orphans property sets or returns the minimum number of visible lines an element must have at the bottom of a page.

Syntax

Setting the widows property:

Object.style.widows="number|inherit"

Returning the widows property:

Object.style.widows

Value Description
number An integer that specifies the minimum number of visible lines. The default value is 2.
inherit The value of the widows property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Only Opera supports the widows property.


Examples

Examples

Change the widows property for printing or print preview:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function ChangeWidows(){
    document.getElementById("p1").style.widows=document.getElementById("widows").value;
}
</script>
<style>
.othercontent{
    width:400px;
    border-top:19cm solid #c3c3c3;
}
@page{
/* Set the print page size */
    size:21cm 27cm;
    margin-top:2cm;
}
@media print{
    .widows{
        widows:2;
    }
}
</style>
</head>
<body>
    
<div class="othercontent">
<input id="widows" value="2"/>
<button onclick="ChangeWidows();">Modify window</button>
<p style="font-size:120%" id="p1">
Modify the window and view print preview<br>
Line 2<br>
Line 3<br>
Line 4<br>
Line 5<br>
Line 6<br>
Line 7<br>
Line 8<br>
</p>
<div class="othercontent"></div>
</div>

</body>
</html>

Try it yourself »


Style 对象参考手册Style Object Other extensions