在我的React应用程序中(使用semanticUI),我有几个组件呈现在视图中,但当用户想要打印页面时(例如通过在浏览器上按Ctrl+P),我只想让其中一个部分可打印。
例如,如果这是用户看到的截图,则在触发浏览器打印时,绿色区域应该显示在打印概述中。
到目前为止,在SCSS文件中,我有:
将不需要的组件添加进去,可以使它们消失,但在打印区域会留下空白。绿色区域没有填满页面,如果这个绿色部分是可滚动的并且应该适用于几页,我只能看到一页(一个A4纸张包含我在屏幕上看到的内容)。
例如,如果这是用户看到的截图,则在触发浏览器打印时,绿色区域应该显示在打印概述中。
到目前为止,在SCSS文件中,我有:
@media print{
.no-print, .no-print *{ display: none !important; }
}
将不需要的组件添加进去,可以使它们消失,但在打印区域会留下空白。绿色区域没有填满页面,如果这个绿色部分是可滚动的并且应该适用于几页,我只能看到一页(一个A4纸张包含我在屏幕上看到的内容)。
拥有
@media print {
.print-content {
display: block;
width: 100%;
height: 100%;
page-break-after: always;
overflow: visible;
}
}
尚未生效,但获得相同的可打印视图。
import React from 'react'
import { Grid, Image } from 'semantic-ui-react'
const GridExampleCelled = () => (
<Grid celled>
{/*another Grid.Row*/}
<Grid.Row>
<Grid.Column width={3}>
<Image src='/images/wireframe/image.png' />
</Grid.Column>
<Grid.Column width={10}> /* This should be the component to print */
<p> EveryThing Wrapped in this Grid should be printed </p>
</Grid.Column>
<Grid.Column width={3}>
<Image src='/images/wireframe/image.png' />
</Grid.Column>
</Grid.Row>
</Grid>
)
export default GridExampleCelled
.no-print
或.print-content
这些类名吗?你自定义的样式(在@media print { ... }
中)只会影响具有这些类名的元素。 - ArneHugo