API 浏览器
CSS 可见性

有一些 CSS 类可供你开箱即用,用于实现常用功能。

¥There are some CSS classes that you can use out of the box for common functionality.

类名描述
disabled光标已更改为通知 ‘disable’,并且不透明度已设置为较低的值。
hiddendisplay 设置为 none。与下文比较 - 类 hidden 表示该元素不会显示,也不会占用布局空间。
invisiblevisibility 设置为 hidden。与上文比较 - 类 invisible 表示该元素不会显示,但仍会占用布局空间。
transparent背景颜色为透明。
dimmed在元素顶部应用深色透明叠加层。不要在已经具有 :after 伪元素的元素上使用。
light-dimmed在元素顶部应用白色透明叠加层。不要在已经具有 :after 伪元素的元素上使用。
ellipsis当空间不足时,截断文本并显示省略号。
ellipsis-2-lines当两行空间不足时,截断文本并显示省略号(仅适用于 Webkit 浏览器)。
ellipsis-3-lines当三行空间不足时,截断文本并显示省略号(仅适用于 Webkit 浏览器)。
z-top将你的元素放置在任何其他组件之上,但位于弹出窗口、工具提示和通知之后。
z-max将你的元素放置在任何其他组件之上(包括抽屉、模态框、通知、布局页眉/页脚等)。

¥Window Width Related

首先,让我们定义断点:​​

¥First of all, let’s define what the breakpoints are:

窗口大小名称最小宽度阈值(像素)最大宽度阈值(像素)
超小xs0px599.99px
sm600 像素1023.99px
Mediummd1024px1439.99px
过大lg1440px1919.99px
超大xl1920px无限

现在来看看与窗口宽度相关的 CSS 类。

¥Now on to the window width related CSS classes.

类名描述
xs仅在超小窗口上显示
sm仅在小窗口上显示
md仅在中型窗口上显示
lg仅在大窗口上显示
xl仅在超大窗口上显示

你还可以显示一些小于指定尺寸的 DOM 元素或组件。大于其中一种大小的文件也相同。只需附加 lt-gt- 前缀,这些前缀来自 “低于” 和 “大于”。示例:lt-md(仅在 xs 和 sm 上显示)、lt-xl(仅在 xs、sm、md 和 lg 窗口上显示)、gt-md(在大于中型窗口上显示):lg 和 xl)。

¥You can also show some DOM element or component if it’s lower than one of the sizes. Same for greater than one of the sizes. Just attach lt- or gt- prefixes, which come from “lower than” and “greater than”. Example: lt-md (display on xs and sm only), lt-xl (display on xs, sm, md and lg windows only), gt-md (display on greater than medium windows: lg and xl).

提示

你可以将可见性类与 inline 类结合使用,用于内联块。

¥You can combine the visibility classes with the inline class for inline-blocks.

示例:<span class="gt-sm inline">...</span>

¥Example: <span class="gt-sm inline">...</span>

提示

例如,如果你想根据 JavaScript 属性显示或隐藏,则可以使用 屏幕插件

¥If you want to e.g. show hide based on JavaScript properties, you can use the Screen Plugin.

¥Platform Related

仅在以下平台可见:

¥Visible only on:

类名描述
desktop-only仅在桌面设备上可见
mobile-only仅在移动设备上可见
native-mobile-only仅在 Cordova/Capacitor 上可见
cordova-only仅在 Cordova 封装的应用上可见
capacitor-only仅在 Capacitor 封装的应用上可见
electron-only仅在 Electron 封装的应用上可见
touch-only仅在支持触控的平台上可见
platform-ios-only仅在 iOS 平台上可见
platform-android-only仅在 A​​ndroid 平台上可见
within-iframe-only仅当整个网站位于 IFRAME 标签下时才可见

隐藏位置:

¥Hide on:

类名描述
desktop-hide在桌面平台上隐藏
mobile-hide在移动设备上隐藏
native-mobile-hide在 Cordova/Capacitor 平台上隐藏
cordova-hide在 Cordova 封装的应用上隐藏
capacitor-hide在 Capacitor 封装的应用上隐藏
electron-hide在 Electron 封装的应用上隐藏
touch-hide在支持触控的平台上隐藏
platform-ios-hide在 iOS 平台上隐藏
platform-android-hide在 Android 平台上隐藏
within-iframe-hide仅当整个网站位于 IFRAME 标签下时隐藏

提示

根据你的需求,你可能还需要查看 平台检测 页面,了解如何使用 JavaScript。后一种方法允许你甚至不渲染 DOM 元素或组件。当渲染过程开销较大时,它很有用。

¥Based on your needs, you might want to also check Platform Detection page to see how you can achieve the same effect using Javascript. This latter method allows you to not even render a DOM element or component. It is useful when the rendering process is expensive.

¥Orientation Related

类名描述
orientation-portrait仅当屏幕方向为纵向时才可见
orientation-landscape仅当屏幕方向为横向时才可见

¥Printing Related

类名描述
print-only仅在印刷媒体上可见 - 在屏幕媒体上隐藏
print-hide在屏幕媒体上可见 - 在印刷媒体上隐藏