在打印中使用 CSS 检测页面方向

Fan*_* Du 1 css printing orientation

我想使用 CSS 样式来检测打印中的页面方向,然后在用户选择不同的方向(横向或纵向)时应用不同的样式。

@media print{ /*portrait*/  /*landscape*/}
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

谢谢

Geo*_*088 7

使用orientation: ...媒体选择器。下面是一个例子:

@media print and (orientation: portrait) {
    /* Your code for portrait orientation */
}
@media print and (orientation: landscape) {
    /* Your code for landscape orientation */
}
Run Code Online (Sandbox Code Playgroud)