简体   繁体   English

HTML,当内容达到一定高度时如何制作可重复的页眉和页脚?

[英]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 DataFooter 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-grouptable-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.

相关问题 固定页脚和页眉时的HTML布局动态内容高度 - HTML Layout Dynamic Content height when Footer and Header are fixed 当div的高度达到一定百分比时更改段落内容 - Change paragraph content when height of a div reaches a certain percentage HTML视频到达特定时间标记时如何触发事件? - How to make events fire when an HTML video reaches a certain time mark? 当div在页面中达到特定高度时 - when div reaches certain height in page 使用html和css打印页面时,如何将页脚和页眉对齐到最小高度? - How do i align footer and header at with minimal height when printing a page using html and css? 如何使用可变高度的主体制作标题/正文/页脚&#39;弹出&#39;div? - How to make header/body/footer 'popup' div with variable height body? 高度达到页面高度的100%后,如何使html div垂直滚动? - How to make a html div vertically scrollable after it's height reaches 100% height of the page? 垂直居中内容区域直到它达到某个高度? - Vertically center a content area until it reaches a certain height? 如何使用Javascript或其他Java方法使某些HTML代码块可重复? - How to make certain block of HTML code repeatable using Javascript or other Java method? 如何使 header、滚动条上的主要内容和页脚对齐视口? - How to make header, main content and footer on scroll snap to viewport?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM