用于指针光标的Bootstrap v4 + css类

w41*_*1 3 36 html css twitter-bootstrap bootstrap-4

pointer:cursor在bootstrap 4中是否有任何css类或属性专门用于按钮或链接?

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="btn btn-success">Sample Button</button>
Run Code Online (Sandbox Code Playgroud)

Vib*_*ube 52

截至 2020 年 6 月,添加role='button'到任何 HTML 标签都会添加cursor: "pointer"到元素样式中。

<span role="button">Non-button element button</span>
Run Code Online (Sandbox Code Playgroud)

关于此功能的官方讨论 - https://github.com/twbs/bootstrap/issues/23709

文档链接 - https://getbootstrap.com/docs/4.5/content/reboot/#pointers-on-buttons

  • 请注意,虽然这可能有效,但您应该仅在元素的角色是按钮时使用它。 (4认同)
  • 这应该是新接受的答案,因为它添加了光标,但不添加与“按钮”相关的其他类 (2认同)

Klo*_*ven 26

更新Bootstrap 4稳定版

该cursor: pointer;规则已经恢复,因此现在默认情况下按钮会将光标悬停在:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<button type="button" class="btn btn-success">Sample Button</button>
Run Code Online (Sandbox Code Playgroud)


不,没有.你需要为此制作一些自定义CSS.

如果您只需要一个看起来像按钮(带指针)的链接,请使用:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<a class="btn btn-success" href="#" role="button">Sample Button</a>
Run Code Online (Sandbox Code Playgroud)

  • 我通过简单地添加实现了效果:role="button" ... 不需要 btn 类。 (7认同)

Har*_*Das 25

不幸的是,截至目前(2019年1月27日),Bootstrap中还没有此类课程。

我浏览了引导程序代码,发现以下使用cursor:pointer的类。似乎将它们中的任何一个专门用于cursor:指针并不是一个好主意。

summary {
  display: list-item;
  cursor: pointer;
}
.btn:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.custom-range::-webkit-slider-runnable-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: #dee2e6;
  border-color: transparent;
  border-radius: 1rem;
}
.custom-range::-moz-range-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: #dee2e6;
  border-color: transparent;
  border-radius: 1rem;
}
.custom-range::-ms-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: transparent;
  border-color: transparent;
  border-width: 0.5rem;
}
.navbar-toggler:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.page-link:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.close:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.carousel-indicators li {
  box-sizing: content-box;
  -ms-flex: 0 1 auto;
  flex: 0 1 auto;
  width: 30px;
  height: 3px;
  margin-right: 3px;
  margin-left: 3px;
  text-indent: -999px;
  cursor: pointer;
  background-color: #fff;
  background-clip: padding-box;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  opacity: .5;
  transition: opacity 0.6s ease;
}
Run Code Online (Sandbox Code Playgroud)

唯一明显的解决方案:

我建议您只是在常见的CSS中创建一个类,例如cursor-pointer。到目前为止,这是简单而优雅的。

summary {
  display: list-item;
  cursor: pointer;
}
.btn:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.custom-range::-webkit-slider-runnable-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: #dee2e6;
  border-color: transparent;
  border-radius: 1rem;
}
.custom-range::-moz-range-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: #dee2e6;
  border-color: transparent;
  border-radius: 1rem;
}
.custom-range::-ms-track {
  width: 100%;
  height: 0.5rem;
  color: transparent;
  cursor: pointer;
  background-color: transparent;
  border-color: transparent;
  border-width: 0.5rem;
}
.navbar-toggler:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.page-link:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.close:not(:disabled):not(.disabled) {
  cursor: pointer;
}
.carousel-indicators li {
  box-sizing: content-box;
  -ms-flex: 0 1 auto;
  flex: 0 1 auto;
  width: 30px;
  height: 3px;
  margin-right: 3px;
  margin-left: 3px;
  text-indent: -999px;
  cursor: pointer;
  background-color: #fff;
  background-clip: padding-box;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  opacity: .5;
  transition: opacity 0.6s ease;
}
Run Code Online (Sandbox Code Playgroud)
.cursor-pointer{
  cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)

  • 只需向您希望在鼠标光标悬停在元素上时具有指针光标的 HTML 元素添加属性 `role="button"` 即可。 (2认同)

Ale*_*ues 24

我通常只添加以下自定义 CSS,W3School 示例以cursor-

.cursor-alias {cursor: alias;}
.cursor-all-scroll {cursor: all-scroll;}
.cursor-auto {cursor: auto;}
.cursor-cell {cursor: cell;}
.cursor-context-menu {cursor: context-menu;}
.cursor-col-resize {cursor: col-resize;}
.cursor-copy {cursor: copy;}
.cursor-crosshair {cursor: crosshair;}
.cursor-default {cursor: default;}
.cursor-e-resize {cursor: e-resize;}
.cursor-ew-resize {cursor: ew-resize;}
.cursor-grab {cursor: -webkit-grab; cursor: grab;}
.cursor-grabbing {cursor: -webkit-grabbing; cursor: grabbing;}
.cursor-help {cursor: help;}
.cursor-move {cursor: move;}
.cursor-n-resize {cursor: n-resize;}
.cursor-ne-resize {cursor: ne-resize;}
.cursor-nesw-resize {cursor: nesw-resize;}
.cursor-ns-resize {cursor: ns-resize;}
.cursor-nw-resize {cursor: nw-resize;}
.cursor-nwse-resize {cursor: nwse-resize;}
.cursor-no-drop {cursor: no-drop;}
.cursor-none {cursor: none;}
.cursor-not-allowed {cursor: not-allowed;}
.cursor-pointer {cursor: pointer;}
.cursor-progress {cursor: progress;}
.cursor-row-resize {cursor: row-resize;}
.cursor-s-resize {cursor: s-resize;}
.cursor-se-resize {cursor: se-resize;}
.cursor-sw-resize {cursor: sw-resize;}
.cursor-text {cursor: text;}
.cursor-w-resize {cursor: w-resize;}
.cursor-wait {cursor: wait;}
.cursor-zoom-in {cursor: zoom-in;}
.cursor-zoom-out {cursor: zoom-out;}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="btn btn-success cursor-pointer">Sample Button</button>
Run Code Online (Sandbox Code Playgroud)


Afz*_*Ali 12

您可以将“按钮”分配给任何 html 标签/元素的角色属性,以在其上放置指针。IE

<html-element role="button" />
Run Code Online (Sandbox Code Playgroud)

  • Vibhor Dube 的答案的副本?! (3认同)

小智 7

我没有足够的声誉来评论相关的答案,但对于阅读这篇文章的人来说;添加 .btn 不仅添加指针光标,还添加了许多其他样式。如果它是一个按钮并且您想要 bootstap 按钮样式,那就太好了,但在其他情况下,它会给其他元素带来很多麻烦。

你能做的最好的事情,就像 Hari Das 建议的那样,我也总是这样做,是添加以下 css:

.cursor-pointer {
  cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)

之后您可以将其添加到任何元素

<div class="cursor-pointer"> .. </div>
Run Code Online (Sandbox Code Playgroud)


Cod*_*ogh 6

我尝试发现,如果您添加一个名为的类,则将鼠标悬停在该元素上btn即可获得该类hand或图标。cursor尝试看看。

例子:

<span class="btn">Hovering over must have mouse cursor set to hand or pointer!</span>
Run Code Online (Sandbox Code Playgroud)

干杯!