是否有任何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:
该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>
不幸的是,截至目前(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
。到目前为止,这是简单而优雅的。
从2020年6月开始,添加role='button'
到任何HTML标签将添加cursor: "pointer"
元素样式。
<span role="button">Non-button element button</span>
关于此功能的正式讨论-https: //github.com/twbs/bootstrap/issues/23709
文档链接-https://getbootstrap.com/docs/4.5/content/reboot/#pointers-on-buttons
我通常只添加以下自定义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>
我没有足够的声誉来评论相关的答案,但是对于那些正在阅读此书的人来说;添加.btn不仅会添加指针光标,还会添加很多其他样式。如果它是一个按钮,并且您想要自举按钮样式,那很好,但是在其他情况下,其他元素会变得很混乱。
您可以做的最好的事情,例如Hari Das建议的,并且我也一直做,就是添加以下CSS:
.cursor-pointer {
cursor: pointer;
}
之后,您可以将其添加到任何元素
<div class="cursor-pointer"> .. </div>
引导程序3-只需添加“ btn ”类就对我有用。
没有指针光标:
<span class="label label-success">text</span>
使用指针光标:
<span class="label label-success btn">text</span>
您可以将“按钮”分配给任何html标记/元素的role属性,以使其指向其上方。即
<html-element role="button" />