如何在打印媒体时显示div,其他时间隐藏?

问题描述 投票:0回答:1

我想用它只打印

#section-to-print
:

@media print {
    body * {
        visibility: hidden;
    }
    #section-to-print, #section-to-print * {
        visibility: visible;
    }
    #section-to-print {
        position: absolute;
        left: 0;
        top: 0;
    }
}

如何扩展它以在屏幕上显示时隐藏

#section-to-print
? 换句话说,它只有在打印介质时才可见。

css media-queries
1个回答
1
投票

将其设置为visibility:hidden,然后@media print可以覆盖它。

#section-to-print, #section-to-print * {
    visibility: hidden;
}
@media print {
    body * {
        visibility: hidden;
    }
    #section-to-print, #section-to-print * {
        visibility: visible;
    }
    #section-to-print {
        position: absolute;
        left: 0;
        top: 0;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.