【问题标题】:fixed header for print not taking full page width固定的打印标题不占用整个页面宽度
【发布时间】:2015-02-16 23:46:36
【问题描述】:

我有一个隐藏的页眉,在打印页面时会显示,但是当我尝试使用 chrome 40 打印它时,它不会占用全宽页面。为什么?

HTML

<div id="header">
    <img id="logo" src="assets/img/brand.png">
    <div id="title">Departamento de diagnostico por imagenes</div>
</div>
<div id="footer">
    <p class="page"></p>
</div>

CSS

#header{
    top:0px;
    right:0px;
    width: 100%;
    height: 45px;
    position:fixed;
    border:1px solid #ccc;
}
#logo{
    position: absolute;
    top: 0;
    left: 0;
    height: 46px;
}
#title{
    position: absolute;
    top: 0;
    right: 0;
    font-size: 18px;
    font-weight: bold;
}
#footer {
    position: fixed;
    left: 50%;
    bottom: 0;
    /*right: 0;*/
    height: 40px;
    text-align: center;
}
#footer .page:after {
    content: counter(page, upper-roman);
    font-size: 18px;
}

更新 我更改为绝对位置,它可以工作,它占据了整个宽度

但现在我意识到它并没有在每一页中重复,即使位置固定

还要注意带有数字页的页脚,由于位置固定,它的居中是错误的,但是当我将其更改为绝对时,它是正确的,但它会进入内容的底部,而不是页面的底部,并且在这两种情况下都不重复在每一页

【问题讨论】:

  • 尝试删除打印样式表上的position: fixed
  • @maioman 没用
  • 能否为页脚添加相关的 HTML 和 CSS?
  • @RamisWachtler 添加了
  • 嗯,似乎对我有用。但是尝试在您的#footer 中将position: fixed 更改为absolute 并应用left: 0; width: 100%;

标签: css printing


【解决方案1】:

去掉fixed的位置,改成absolute,我也把#logoheight改成了100%而不是46px

片段

body {
  font-family: Arial, sans-serif;
}
#header {
  top: 0px;
  right: 0px;
  width: 100%;
  height: 45px;
  position: absolute;
  border: 1px solid #ccc;
}
#logo {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
}
#title {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 18px;
  font-weight: bold;
}
h3 {
  margin-top: 100px;
}
#header-table {
  top: 150px;
  /*Change to 0px when supposed to use*/
  right: 0px;
  width: 100%;
  height: 45px;
  position: absolute;
  border: 1px solid #ccc;
  display: table;
}
#logo-cell {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
}
#title-cell {
  display: table-cell;
  vertical-align: middle;
  font-size: 18px;
  font-weight: bold;
  text-align: right;
}
<div id="header">
  <img id="logo" src="http://img3.wikia.nocookie.net/__cb20140501181347/creepypasta/images/f/f6/Grumpy_Cat.jpg">
  <div id="title">Departamento de diagnostico por imagenes</div>
</div>
<h3>Display: Table, if your title should be vertically centered</h3>
<div id="header-table">
  <img id="logo-cell" src="http://img3.wikia.nocookie.net/__cb20140501181347/creepypasta/images/f/f6/Grumpy_Cat.jpg">
  <div id="title-cell">Departamento de diagnostico por imagenes</div>
</div>

【讨论】:

  • 好解决位置绝对,我更新了问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-17
  • 1970-01-01
  • 2019-04-30
  • 2018-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多