CSS ngắt trước thuộc tính
Ví dụ
Luôn chèn ngắt trang trước phần tử <h1>:
@media print
{
h1 {
break-before: always;
}
}
Định nghĩa và cách sử dụng
Thuộc tính break-before
chỉ định xem có nên ngắt trang, ngắt cột hoặc ngắt vùng trước phần tử được chỉ định hay không.
Thuộc tính break-before
mở rộng thuộc tính page-break-before
của CSS2.
Bằng cách sử dụng break-before
, bạn có thể yêu cầu trình duyệt ngắt trang, cột hoặc vùng trước phần tử mà thuộc tính break-before
được áp dụng hoặc tránh phần tử bị phân tách và trải dài trên hai trang.
Giá trị mặc định: | tự động |
---|---|
Thừa hưởng: | KHÔNG |
Hoạt hình: | KHÔNG. Đọc về hoạt hình |
Phiên bản: | CSS3 |
Cú pháp JavaScript: | đối tượng .style.breakBefore="luôn luôn" |
Hỗ trợ trình duyệt
Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ thuộc tính.
Property | |||||
---|---|---|---|---|---|
break-before | 50.0 | 10.0 | 65.0 | 10.0 | 37.0 |
Cú pháp CSS
break-before: auto|all|always|avoid|avoid-column|avoid-page|avoid-region|column|left|page|recto|region|right|verso|initial|inherit;
Giá trị tài sản
Value | Description |
---|---|
auto | Default. Automatic page/column/region break before the element |
all | Always insert a page-break right before the principal box |
always | Always insert a page-break before the element |
avoid | Avoid a page/column/region break before the element |
avoid-column | Avoid a column-break before the element |
avoid-page | Avoid a page-break before the element |
avoid-region | Avoid a region-break before the element |
column | Always insert a column-break before the element |
left | Insert one or two page-breaks before the element so that the next page is formatted as a left page |
page | Always insert a page-break before the element |
recto | Insert one or two page-breaks before the principal box so that the next page is formatted as a recto page |
region | Always insert a region-break before the element |
right | Insert one or two page-breaks before the element so that the next page is formatted as a right page |
verso | Insert one or two page-breaks before the principal box so that the next page is formatted as a verso page |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Thêm ví dụ
Ví dụ
Để đảm bảo rằng tất cả các chương mới sẽ bắt đầu ở đúng trang (như trong sách) khi được in, bạn có thể sử dụng break-Before: right cho tất cả phần tử <h1>:
@media print
{
h1 {
break-before: right;
}
}
Ví dụ
Luôn chèn dấu ngắt vùng trước các phần tử <ul> trong một vùng:
.region ul {
break-before: region;
}
}