引导光标的Bootstrap V4 + CSS类


77

是否有任何CSS类或属性为pointer:cursor引导4专为按钮或链接?

<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>

Answers:


53

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>


不,没有。您需要为此制作一些自定义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>


1
更好,谢谢...在这里,href =“#”是必需的..虽然没有问题..工作..谢谢
w411 17/11/13

我仅通过添加以下内容即可达到效果:role =“ button” ...不需要btn类。
马特·沃勒

仅供参考:按钮的禁用状态被打破(有指针),但链接却无效(没有指针):在FF76中的getbootstrap.com/docs/4.4/components/buttons上进行了测试,并且使用webjar的4.4.1-1在我的应用中具有相同的行为
德里克·怀特

53

不幸的是,截至目前(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;
}

唯一明显的解决方案:

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

.cursor-pointer{
  cursor: pointer;
}
<div class="cursor-pointer">Hover on  me</div>



21

我通常只添加以下自定义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;}
<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>


7

我没有足够的声誉来评论相关的答案,但是对于那些正在阅读此书的人来说;添加.btn不仅会添加指针光标,还会添加很多其他样式。如果它是一个按钮,并且您想要自举按钮样式,那很好,但是在其他情况下,其他元素会变得很混乱。

您可以做的最好的事情,例如Hari Das建议的,并且我也一直做,就是添加以下CSS:

.cursor-pointer {
  cursor: pointer;
}

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

<div class="cursor-pointer"> .. </div>

bootstrap 4.3已经解决了这个问题getbootstrap.com/docs/4.3/components/buttons/#examples
w411

3

我试过,结果发现,如果添加了一个类调用btn你可以得到handcursor图标,如果你悬停鼠标到该元素。尝试看看。

例:

<span class="btn">Hovering over must have mouse cursor set to hand or pointer!</span>

干杯!


3

引导程序3-只需添加“ btn ”类就对我有用

没有指针光标:

<span class="label label-success">text</span>

使用指针光标:

<span class="label label-success btn">text</span>

这是我所见过的与Bootstrap相关的最糟糕的解决方法。
Vibhor Dube

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.