English 中文(简体)
利用特别安全局隐藏印刷材料
原标题:Use CSS to hide contents on print
  • 时间:2011-01-27 13:31:24
  •  标签:
  • css
  • printing

我的眼光是寻找一种容易的方式来掩盖除某种四分五裂及其内容外的一切。

<html>
  <head></head>
  <body>
    <div class="header">...</div>
    <div class="menu">...</div>
    <div class="content">...</div>
    <div class="footer">...</div>
  </body>.
</html>

因此,例如,如果我只想打印div.content,我就这样做:

.header, .menu, .footer {
  display: none;
}

如果布局复杂,就会变得令人迷惑。 是否比较容易与安保部合作?

最佳回答

我这样做的方式是:不使用假肢和直接祖先(儿童)

/* hide all children of body that are not #container */
body > *:not(#container) {
  display: none;
}
/* hide all children of #container that are not #content */
#container > *:not(#content) {
  display: none;
}
/* and so on, until you reach a div that you want to print */
#content > *:not(#print_me) {
  display: none;
}

这样,除你想要在非常复杂的布局印刷的东西外,你就可以消除一切。 :这里没有非常有效率,因为它关注今后对你所作的任何修改。

问题回答
@media print {
.noPrint {
    display:none;
  }
}

现在,你需要将“<代码>noPrint”适用于你想要在印刷中藏匿的内容。


采用专供印刷的风格表,并将其媒体称谓<条码><>印本/代码>,是良好做法。

<>>Example:

<link rel="stylesheet" type="text/css" href="print.css" media="print" />

• 指定一个单独的中央支助事务文件,界定印刷网页时的行为。

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

之后在档案中仅界定:

.header, .menu, .footer { display: none; }

你们可以使用课堂。

.classHide{display: none}

视你使用的语言而定,如果=真话,你可以增加一个头盔、菜单和鞋子。

So you won t need to use another css file.

视您的超文本结构(以及各位需要支持的浏览器,因为国际电子计算方法6赢得了支持),你可以隐藏所有顶级干iv,只是显示你想要显示的:

body > div {
   display: none;
}

#content {
  display: block;
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签