Joh*_*ith 116 html css twitter-bootstrap
我要做的是将工具提示颜色更改为红色.但是,我也希望有多种其他颜色,所以我不想简单地替换原始工具提示的颜色.
我该怎么做呢?
Pra*_*man 169
你可以这样使用:
<a href="#" data-toggle="tooltip" data-placement="bottom"
title="" data-original-title="Tooltip on bottom"
class="red-tooltip">Tooltip on bottom</a>
Run Code Online (Sandbox Code Playgroud)
在CSS中:
.tooltip-arrow,
.red-tooltip + .tooltip > .tooltip-inner {background-color: #f00;}
Run Code Online (Sandbox Code Playgroud)
Moeen MH:使用最新版本的bootstrap,你可能需要这样做才能摆脱黑色箭头:
.red-tooltip + .tooltip.top > .tooltip-arrow {background-color: #f00;}
Run Code Online (Sandbox Code Playgroud)
用于Bootstrap 4:
.bs-tooltip-auto[x-placement^=bottom] .arrow::before,
.bs-tooltip-bottom .arrow::before {
border-bottom-color: #f00; /* Red */
}
Run Code Online (Sandbox Code Playgroud)
完整片段:
$(function() {
$('[data-toggle="tooltip"]').tooltip()
})Run Code Online (Sandbox Code Playgroud)
.tooltip-main {
width: 15px;
height: 15px;
border-radius: 50%;
font-weight: 700;
background: #f3f3f3;
border: 1px solid #737373;
color: #737373;
margin: 4px 121px 0 5px;
float: right;
text-align: left !important;
}
.tooltip-qm {
float: left;
margin: -2px 0px 3px 4px;
font-size: 12px;
}
.tooltip-inner {
max-width: 236px !important;
height: 76px;
font-size: 12px;
padding: 10px 15px 10px 20px;
background: #FFFFFF;
color: rgb(0, 0, 0, .7);
border: 1px solid #737373;
text-align: left;
}
.tooltip.show {
opacity: 1;
}
.bs-tooltip-auto[x-placement^=bottom] .arrow::before,
.bs-tooltip-bottom .arrow::before {
border-bottom-color: #f00;
/* Red */
}Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="tooltip-main" data-toggle="tooltip" data-placement="top" data-original-title="Hello world"><span class="tooltip-qm">?</span></div>
<style>
.bs-tooltip-auto[x-placement^=bottom] .arrow::before,
.bs-tooltip-bottom .arrow::before {
border-bottom-color: #f00;
/* Red */
}
</style>Run Code Online (Sandbox Code Playgroud)
tec*_*rek 109
Bootstrap 2
如果您还想更改插入符号/箭头,请执行以下操作:
.red-tooltip + .tooltip > .tooltip-inner {background-color: #f00;}
.red-tooltip + .tooltip > .tooltip-arrow {border-bottom-color: #f00;}
Run Code Online (Sandbox Code Playgroud)
要么
.red-tooltip + .tooltip > .tooltip-inner, .red-tooltip + .tooltip > .tooltip-arrow {background-color: #f00;}
Run Code Online (Sandbox Code Playgroud)
jsFiddle:http://jsfiddle.net/technotarek/2htZe/
更新:Bootstrap 3
您必须具体针对Bootstrap 3中工具提示的方向.例如:
.tooltip.top .tooltip-inner {
background-color:red;
}
.tooltip.top .tooltip-arrow {
border-top-color: red;
}
Run Code Online (Sandbox Code Playgroud)
使用Bootstrap 3的所有工具提示方向的jsFiddle:http://jsfiddle.net/technotarek/L2rLE/
小智 55
对我有用的唯一方法:
$(document).ready(function() {
//initializing tooltip
$('[data-toggle="tooltip"]').tooltip();
});Run Code Online (Sandbox Code Playgroud)
.tooltip-inner {
background-color: #00acd6 !important;
/*!important is not necessary if you place custom.css at the end of your css calls. For the purpose of this demo, it seems to be required in SO snippet*/
color: #fff;
}
.tooltip.top .tooltip-arrow {
border-top-color: #00acd6;
}
.tooltip.right .tooltip-arrow {
border-right-color: #00acd6;
}
.tooltip.bottom .tooltip-arrow {
border-bottom-color: #00acd6;
}
.tooltip.left .tooltip-arrow {
border-left-color: #00acd6;
}Run Code Online (Sandbox Code Playgroud)
<!--jQuery-->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!--tether-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<!--Bootstrap-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<!--Tooltip Example-->
<div style="padding:50px;">
<span class="fa-stack fa-lg" data-toggle="tooltip" data-placement="right" title="custom colored tooltip">hover over me
</span>
</div>Run Code Online (Sandbox Code Playgroud)
小智 10
对于箭头颜色,您可以使用:
.tooltip .tooltip-arrow {border-top: 5px solid red !important;}
Run Code Online (Sandbox Code Playgroud)
小智 10
这是boostrap中的工具提示代码......
.tooltip {
position: absolute;
z-index: 1070;
display: block;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 12px;
font-style: normal;
font-weight: normal;
line-height: 1.42857143;
text-align: left;
text-align: start;
text-decoration: none;
text-shadow: none;
text-transform: none;
letter-spacing: normal;
word-break: normal;
word-spacing: normal;
word-wrap: normal;
white-space: normal;
filter: alpha(opacity=0);
opacity: 0;
line-break: auto;
}
.tooltip.in {
filter: alpha(opacity=90);
opacity: .9;
}
.tooltip.top {
padding: 5px 0;
margin-top: -3px;
}
.tooltip.right {
padding: 0 5px;
margin-left: 3px;
}
.tooltip.bottom {
padding: 5px 0;
margin-top: 3px;
}
.tooltip.left {
padding: 0 5px;
margin-left: -3px;
}
.tooltip-inner {
max-width: 200px;
padding: 3px 8px;
color: #fff;
text-align: center;
background-color: #000;
border-radius: 4px;
}
.tooltip-arrow {
position: absolute;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
}
.tooltip.top .tooltip-arrow {
bottom: 0;
left: 50%;
margin-left: -5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-left .tooltip-arrow {
right: 5px;
bottom: 0;
margin-bottom: -5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.top-right .tooltip-arrow {
bottom: 0;
left: 5px;
margin-bottom: -5px;
border-width: 5px 5px 0;
border-top-color: #000;
}
.tooltip.right .tooltip-arrow {
top: 50%;
left: 0;
margin-top: -5px;
border-width: 5px 5px 5px 0;
border-right-color: #000;
}
.tooltip.left .tooltip-arrow {
top: 50%;
right: 0;
margin-top: -5px;
border-width: 5px 0 5px 5px;
border-left-color: #000;
}
.tooltip.bottom .tooltip-arrow {
top: 0;
left: 50%;
margin-left: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-left .tooltip-arrow {
top: 0;
right: 5px;
margin-top: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
.tooltip.bottom-right .tooltip-arrow {
top: 0;
left: 5px;
margin-top: -5px;
border-width: 0 5px 5px;
border-bottom-color: #000;
}
Run Code Online (Sandbox Code Playgroud)
小智 10
对于bootstrap4,我使用了代码:
.tooltip-inner {
background-color: #color !important;
color: #color ;
}
.bs-tooltip-top .arrow::before, .bs-tooltip-auto[x-placement^="top"] .arrow::before {
border-top-color: #color !important;
}
.bs-tooltip-right .arrow::before, .bs-tooltip-auto[x-placement^="right"] .arrow::before {
border-right-color: #color !important;
}
.bs-tooltip-bottom .arrow::before, .bs-tooltip-auto[x-placement^="bottom"] .arrow::before {
border-bottom-color: #color !important;
}
.bs-tooltip-left .arrow::before, .bs-tooltip-auto[x-placement^="left"] .arrow::before {
border-left-color: #color !important;
}Run Code Online (Sandbox Code Playgroud)
这对我有用。
.tooltip .arrow:before {
border-top-color: #008ec3 !important;
}
.tooltip .tooltip-inner {
background-color: #008ec3;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我的jQuery修复:
HTML:
<a href="#" data-toggle="tooltip" data-placement="right" data-original-title="some text">
<span class="glyphicon glyphicon-question-sign"></span>
</a>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('[data-toggle="tooltip"]').hover(function(){
$('.tooltip-inner').css('min-width', '400px');
$('.tooltip-inner').css('color', 'red');
});
Run Code Online (Sandbox Code Playgroud)
需要注意的是,从Bootstrap 4开始,您可以直接在Bootstrap Sass变量文件中自定义这些样式,因此在_variables.scss中,您可以使用以下选项:
//== Tooltips
//
//##
// ** Tooltip max width
$tooltip-max-width: 200px !default;
// ** Tooltip text color
$tooltip-color: #fff !default;
// ** Tooltip background color
$tooltip-bg: #000 !default;
$tooltip-opacity: .9 !default;
// ** Tooltip arrow width
$tooltip-arrow-width: 5px !default;
// ** Tooltip arrow color
$tooltip-arrow-color: $tooltip-bg !default;
Run Code Online (Sandbox Code Playgroud)
参见此处:http : //v4-alpha.getbootstrap.com/getting-started/options/
最好在Sass中工作,并在使用Grunt或Gulp构建工具时进行编译。
上述答案在 Bootstrap v5.1.1 中都不适合我。我将一些损坏的解决方案放在一起,并在纯 CSS 中得到了以下工作解决方案:
.tooltip-inner {
background-color: red !important; /* Set box color to red */
color: black !important; /* Set text color to black */
}
.tooltip.bs-tooltip-top .tooltip-arrow::before {
border-top-color: red; /* Set arrow color to red */
}
.tooltip.bs-tooltip-bottom .tooltip-arrow::before {
border-bottom-color: red; /* Set arrow color to red */
}
.tooltip.bs-tooltip-start .tooltip-arrow::before {
border-left-color: red; /* Set arrow color to red */
}
.tooltip.bs-tooltip-end .tooltip-arrow::before {
border-right-color: red; /* Set arrow color to red */
}
Run Code Online (Sandbox Code Playgroud)
从 Bootstrap 5.2 开始,可以通过CSS 变量配置工具提示。
new bootstrap.Tooltip(document.querySelector('[data-bs-toggle="tooltip"]'));
// initialize tooltipRun Code Online (Sandbox Code Playgroud)
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
<style>
.tooltip-success {
--bs-tooltip-bg: var(--bs-success); /* or hardcode any color */
}
</style>
<button type="button" class="btn btn-success" data-bs-toggle="tooltip"
data-bs-custom-class="tooltip-success"
data-bs-title="Some tooltip title" data-bs-placement="bottom">
Success tooltip
</button>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
277796 次 |
| 最近记录: |