Thuộc tính kiểu góa phụ
Thí dụ
Thay đổi các widget và kiểm tra bản in hoặc xem trước bản in:
<html>
<head>
<script>
function ChangeWidows()
{
document.getElementById("p1").style.widows = document.getElementById("widows").value;
}
</script>
<style>
.othercontent
{
width: 400px;
border-top: 19cm solid #c3c3c3;
}
@page
{
/* set size of printed 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();">Change widows</button>
<p style="font-size:120%" id="p1">
Change widows and see the 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">
</body>
</html>
Hãy tự mình thử »
Định nghĩa và Cách sử dụng
Thuộc tính widows đặt hoặc trả về số dòng tối thiểu cho một phần tử phải hiển thị ở đầu trang (để in hoặc xem trước bản in).
Thuộc tính widows chỉ ảnh hưởng đến các phần tử cấp khối.
Mẹo: widows: 5 có nghĩa là ít nhất 5 dòng phải hiển thị bên dưới ngắt trang.
Mẹo: Xem thuộc tính mồ côi để đặt hoặc trả về số dòng tối thiểu cho một phần tử phải hiển thị ở cuối trang.
Hỗ trợ trình duyệt
Property | |||||
---|---|---|---|---|---|
widows | Yes | Not supported | Not supported | Not supported | Yes |
Cú pháp
Trả lại tài sản góa phụ:
object.style.widows
Đặt thuộc tính góa phụ:
object.style.widows = "number|initial|inherit"
Giá trị tài sản
Value | Description |
---|---|
number | An integer that specifies the minimum number of visible lines. Negative values are not allowed. The default value is 2 |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Chi tiết kỹ thuật
Giá trị mặc định: | 2 |
---|---|
Giá trị trả lại: | Một chuỗi, đại diện cho số dòng tối thiểu để in ở đầu trang |
Phiên bản CSS | CSS2 |
❮ Đối tượng phong cách