[英]HTML, How to make repeatable header and footer when content reaches certain height?
Lets say that we have HTML template that has that kind of structure:假设我们有具有这种结构的 HTML 模板:
-------------
|Header Data|
-------------
| |
| Main Data |
| |
-------------
|Footer Data|
-------------
Header Data
, Main Data
and Footer Data
have fixed height value. Header Data
, Main Data
和Footer Data
具有固定的高度值。
However when Main Data
starts to exceed its fixed height value, it should turn into something like this:然而,当Main Data
开始超过其固定高度值时,它应该变成这样:
-------------
|Header Data|
-------------
| |
| MainData1 |
| |
-------------
|Footer Data|
-------------
-------------
|Header Data|
-------------
| |
| MainData2 |
| |
-------------
|Footer Data|
-------------
Is it possible to do that kind of thing only by using HTML and CSS?是否可以仅通过使用 HTML 和 CSS 来做那种事情?
For @media screen
, you should use a single <header>
and <footer>
and make the contents scrollable between the two.对于@media screen
,您应该使用单个<header>
和<footer>
并使内容可在两者之间滚动。
For @media print
, the obsolete solution (but it always worked) was to place everything in a <table>
and use <thead>
and <tfoot>
elements with display
values of table-header-group
and table-footer-group
, respectively.对于@media print
,过时的解决方案(但它总是有效)是将所有内容放在<table>
并使用<thead>
和<tfoot>
元素,分别具有table-header-group
和table-footer-group
display
值.
The modern solution for @media print
, however, is to use running elements :然而,@ @media print
的现代解决方案是使用运行元素:
header {
position: running(header);
}
footer {
position: running(footer);
}
@page {
@top-center {
content: element(header);
}
@bottom-center {
content: element(footer);
}
}
For details on how to use the @page
model, please refer to the official documentation . @page
模型的具体使用方法请参考官方文档。 Also note its current browser support is slightly below 80% , globally.另请注意,其当前的浏览器支持率略低于80% ,在全球范围内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.