从打印版本中删除阴影

Uno*_*Ame 1 html css

我在http://www.canadaiplawyer.com/上有这个代码,希望网站的印刷版本没有主(纸)div周围的阴影:

@media print{
  #content, #endpage, #startpage {
    -webkit-box-shadow: none;
    -moz-box-shadow:    none;
    box-shadow:         none; 
  }
}
Run Code Online (Sandbox Code Playgroud)

有没有理由说这不起作用,打印时我仍然得到阴影?

Ove*_*ous 10

我看起来阴影实际上已经开启#nonfooter,而不是开启#content.您可能想要使用:

@media print{
  #nonfooter {
    -webkit-box-shadow: none;
    -moz-box-shadow:    none;
    box-shadow:         none; 
  }
}
Run Code Online (Sandbox Code Playgroud)

此外,确保@media标记所有正常声明之后,以确保它具有更高的特异性.(如果它位于不同的CSS文件中,请将<link>标记放在正常的文件之后.)


Mik*_*ind 7

用得很重要.下面的代码是打印样式表的标准.

/* ==|== print styles =======================================================
Print styles.
Inlined to avoid required HTTP connection: h5bp.com/r
========================================================================== */

@media print {
  * { background: transparent !important; color: black !important; box-shadow:none !important; text-shadow: none !important; filter:none !important; -ms-filter: none !important; } /* Black prints faster: h5bp.com/s */
  a, a:visited { text-decoration: underline; }
  a[href]:after { content: " (" attr(href) ")"; }
  abbr[title]:after { content: " (" attr(title) ")"; }
  .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; } /* Don't show links for images, or javascript/internal links */
  pre, blockquote { border: 1px solid #999; page-break-inside: avoid; }
  thead { display: table-header-group; } /* h5bp.com/t */
  tr, img { page-break-inside: avoid; }
  img { max-width: 100% !important; }
  @page { margin: 0.5cm; }
  p, h2, h3 { orphans: 3; widows: 3; }
  h2, h3 { page-break-after: avoid; }
}
Run Code Online (Sandbox Code Playgroud)