Bootstrap V5.3 中文手册

Interactions 交互

用于更改用户与网站内容交互方式的实用程序类。

文本选择

更改用户与内容交互时选择内容的方式。

当用户点击时,该段落将被完全选中。

此段落具有默认选择行为。

当用户点击此段落时,该段落将无法选择。

[HTML全文]
<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-none">This paragraph will not be selectable when clicked by the user.</p>

指针事件

Bootstrap 提供 和 类来防止或添加元素交互。.pe-none.pe-auto

无法点击此链接

可以单击此链接(这是默认行为)。

无法单击此链接,因为该属性是从其父级继承的。但是,此链接有一个类,可以单击。pointer-eventspe-auto

[HTML全文]
<p><a href="#" class="pe-none" tabindex="-1" aria-disabled="true">This link</a> can not be clicked.</p>
<p><a href="#" class="pe-auto">This link</a> can be clicked (this is default behavior).</p>
<p class="pe-none"><a href="#" tabindex="-1" aria-disabled="true">This link</a> can not be clicked because the <code>pointer-events</code> property is inherited from its parent. However, <a href="#" class="pe-auto">this link</a> has a <code>pe-auto</code> class and can be clicked.</p>

类(及其设置的 CSS 属性)仅阻止与指针(鼠标、手写笔、触摸)的交互。默认情况下,链接和控件对于键盘用户来说仍然是可聚焦和可作的。为了确保即使对于键盘用户来说,它们也被完全中和,您可能需要添加其他属性,例如(以防止他们接收键盘焦点)和(传达它们被有效禁用给辅助技术的事实),并可能使用 JavaScript 来完全防止它们可作。.pe-nonepointer-events.pe-nonetabindex="-1"aria-disabled="true"

如果可能,更简单的解决方案是:

  • 对于表单控件,请添加 HTML 属性。disabled
  • 对于链接,请删除该属性,使其成为非交互式锚点或占位符链接。href

CSS系统

Sass 实用程序 API

交互实用程序在我们的实用程序 API 中声明。了解如何使用实用工具 API。scss/_utilities.scss

"user-select": (
  property: user-select,
  values: all auto none
),
"pointer-events": (
  property: pointer-events,
  class: pe,
  values: none auto,
),