internet-explorer-9 - 白色背景 div 在 IE9 打印预览中是透明的

标签 internet-explorer-9 printf

我有一个黑色文本和白色背景的 div。在 IE9 中显示正常。但是,在打印预览中,白色背景是透明的。在 Chrome、Firefox 和 Safari 中运行良好。有任何想法吗?

下面的链接显示了页面。显示没问题,但 map 右下角的白框在打印预览时背景透明。

http://www.mycoursewalk.com/course_walk/print/426

谢谢,

缺口,

最佳答案

默认情况下,IE 不打印背景图像和颜色。有一个设置,您可以更改为打印网页的背景图像和颜色 [文件> 打印预览> 页面设置(齿轮图标)]。

我处于类似的情况,我无法控制客户端的浏览器设置。在尝试了许多其他方法后,我最终使用了以下逻辑:-

  • 添加了一个图像(1px x 1px,白色),绝对位置在顶部 0 和左侧 0。
  • 将其设置为在@media 屏幕中不显示{ .div {display: none} 并在@media print{ 中显示块{ .div {display: block}
  • 使用 javaScript 将图像的高度(在您的情况下也可能需要宽度)设置为与文本所在 div 的高度完全相同: $('#whiteBg').height($('#content').height ());

  • html:
    <body>
        <div id="wrapper"> <!-- not necessary -->
            <img scr="./img/white.png" id="whiteBg" />
            <div id="content">
                <!-- content here -->
            </div>
        </div>
        <div id="footer">
        </div>
    </body>
    

    css:
    @media screen {
        #whiteBg {
            display: none;
        }
    }
    
    @media print {
       #whiteBg {
          display: block;
          position: absolute;
          top: 0;
          left: 0;
          z-index: -1; //to send it to the background
       }
    }
    

    查询:
     @('#whiteBg').height(  $('#content')).height()  );
    

    我正在使用此代码在打印输出的最后一页底部设置页脚。我的每一页都有页脚,上面有内容(文本),就像你的一样。我使用白色背景来隐藏除最后一页之外的所有页脚。 HTML footer on bottom of all pages of HTML print out in IE

    关于internet-explorer-9 - 白色背景 div 在 IE9 打印预览中是透明的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11766605/

    相关文章:

    Java:printf 语句中的文字百分号

    html - ie9/CSS : Flyout menu not working in ie9, 但在 Firefox/Chrome 中看起来不错

    jquery - <select> 只显示所选选项的第一个字符

    css - IE9 CSS居中定位

    c - 使用 C 打印行而不覆盖尚未在终端中提交的用户输入

    c - 初学者关于C中fopen的另一个问题

    c - printf 给出错误的输出

    javascript - 对 Flash 的外部接口(interface)调用在 IE9 中不起作用

    jquery - 对象没有方法 'placeholder'

    c++ - tictactoe 游戏没有运算符 "=="匹配这些操作数