Latest web development tutorials

HTML DOM Style widows property

Style Object Reference Style Objects

Definition and Usage

widows property sets or returns must be a minimum number of elements (for printing or print preview) at the top of the page visible rows.

widows property only affects block-level elements.

Tip: widows: 5 means that at least five rows must be visible below the page break.

Tip: orphans property sets or returns a minimum number of elements must be visible at the bottom line of the page.

grammar

Setting widows properties:

Object.style.widows="number|inherit"

Back widows properties:

Object.style.widows

描述
number 一个规定可见行的最小数量的整数。默认值是 2。
inherit widows 属性的值从父元素继承。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Only Opera supports widows property.


Examples

Examples

Change the print or print preview widows properties:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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{
    /* 设置打印页面大小 */
    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();">修改窗口</button>
<p style="font-size:120%" id="p1">
修改窗口并且查看打印预览<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"


Style Object Reference Style Objects