| Class | Styles |
|---|---|
| .user-select-all | -webkit-user-select: all; user-select: all; |
| .user-select-auto | -webkit-user-select: auto; user-select: auto; |
| .user-select-text | -webkit-user-select: text; user-select: text; |
| .user-select-none | -webkit-user-select: none; user-select: none; |
概述
使用用户选择工具类更改用户与内容交互时内容的选中方式。
基本用法
This paragraph will be entirely selected when clicked by the user.
This paragraph has default select behavior.
This paragraph will only allow the text to be selected when clicked by the user, even if the CSS user-select property is set to something else.
This paragraph will not be selectable when clicked by the user.
<p class="user-select-all">This paragraph will be entirely selected when clicked by the user.</p>
<p class="user-select-auto">This paragraph has default select behavior.</p>
<p class="user-select-text">This paragraph will only allow the text to be selected when clicked by the user, even if the CSS <code>user-select</code> property is set to something else.</p>
<p class="user-select-none">This paragraph will not be selectable when clicked by the user.</p>使用场景
.user-select-all- 适用于代码片段、ID 或用户可能希望整体复制的其他内容.user-select-auto- 浏览器默认行为,允许正常选择文本.user-select-text- 强制文本保持可选,适用于覆盖祖先元素设置的user-select: none.user-select-none- 阻止文本选择,适用于 UI 元素、按钮或装饰性文本
无障碍说明: 使用 user-select: none 时请小心,因为它可能干扰辅助技术和键盘导航。请确保重要内容仍可通过其他方式访问。
CSS
Sass 工具类 API
用户选择工具类在我们的工具类 API 中于 scss/_utilities.scss 内声明。了解如何使用工具类 API。
"user-select": (
property: user-select,
values: all auto text none
),