【问题标题】:Apply media query style to media print?将媒体查询样式应用于媒体打印?
【发布时间】:2014-07-08 08:01:23
【问题描述】:

我有一个 CSS 文档,其中包含部分“正常”的 css 以及在调整窗口大小时对 css 所做的一些更改:

@media only screen and (min-width: 400px) and (max-width: 767px) {

/* css */

}

现在当我打印我的 HTML 页面时,它只使用“正常”的 css。

但是,在打印页面时,我想使用“普通”CSS PLUS 来自此媒体查询的部分。

有没有办法做到这一点?

【问题讨论】:

  • 在 css 包含标签中添加 media="print"
  • 你的意思是我必须改写@media screen, print
  • 所以我只是将我的媒体查询 CSS 复制到一个新的 @media print?
  • @2339870 是的,复制/粘贴,完成:)

标签: html css printing media-queries


【解决方案1】:

只需在@media 规则中添加一个逗号,后跟print,如下所示:

@media only screen and (min-width: 400px) and (max-width: 767px), print {

/* css */

}

【讨论】:

    【解决方案2】:

    试试这个

    html

     <header>
         <h1>header</h1>
     </header>
    <section>
      <div class="container clearfix">
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
        <div class="item"> ITEM1 </div>
     </div>
    </section>
     <footer>
       <h1>footer</h1>
    </footer>
    

    //css

    @media screen and (max-width:420px){
      .item{
        color:red;
      }
    }
    @media  screen and (min-width: 321px) and (max-width:960px){
       .item{
        color:green;
       }
    }
     @media screen and (min-width: 720px) and (max-width:1024px){
        .item{
         color:blue;
       }
     }
    @media screen and (min-width:1024px){
      .item{
         color:orchid;
       }
    }
    

    DEMO

    【讨论】:

    • 除了“打印”这个词之外,这与其他任何东西有什么关系?
    猜你喜欢
    • 2014-11-26
    • 2017-11-19
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2013-05-11
    • 2014-03-11
    • 2015-10-01
    • 1970-01-01
    相关资源
    最近更新 更多