【问题标题】:How can I make Twitter Bootstrap tooltips look like the popovers (without the title line)?如何使 Twitter Bootstrap 工具提示看起来像弹出框(没有标题行)?
【发布时间】:2013-04-24 14:15:51
【问题描述】:

我想将Twitter Bootstrap tooltip styles 替换为popover styles。我该怎么做?

工具提示默认如下所示:

弹出框默认是这样的:

我希望我的工具提示是白色的,带有灰色边框,就像弹出框一样。

你能帮忙吗?

【问题讨论】:

  • 您是否尝试过将工具提示 css 替换为 popover css?
  • 也许您可以在悬停时显示弹出框而不是工具提示?示例:stackoverflow.com/a/12343706/291541
  • 对不起,我要问你为什么不使用所有的弹出框? :)
  • @BillyMoat,是的,我也在使用 Popovers。 ;) 但我计划将工具提示作为可悬停的简化工具提示(只有文本,一行,更小的填充,更小的文本)。我可以很好地更改工具提示的背景。但我无法弄清楚边界。
  • 您可以使用$('#my-thing').popover({trigger: 'hover'}); 使鼠标悬停在弹出窗口

标签: html css twitter-bootstrap


【解决方案1】:

如果您想更改工具提示本身的样式,您必须在引导程序的 css 文件中编辑 .tooltip-inner 类,或者用您自己的类覆盖 .tooltip-inner 类。

边框的一个例子是:

.tooltip-inner {
    border: solid 1px #ccc;
}

【讨论】:

  • 谢谢。我添加了背景和颜色样式,以及 tooltiparrowcolor 变量。但是,我无法获得箭头周围的边框或工具提示内部前面的箭头。相反,箭头落在边界之外。你能用整个包裹为我指明正确的方向吗?
  • .tooltip-arrow 类控制箭头的颜色、大小和位置。您不能为箭头添加边框,因为边框是形成箭头形状的原因。但是,您可以将箭头高 1 像素,这样边框就不会覆盖箭头。为此,请将.tooltip.top .tooltip-arrow 部分中的bottom:0px 更改为bottom:1px(如果您使用的是顶部工具提示等)。
【解决方案2】:

我是这样工作的:

添加到 variables.less

@tooltipArrowOuterWidth:  @tooltipArrowWidth + 1;
@tooltipArrowOuterColor:  rgba(0,0,0,.25);

添加到自定义 LESS 文件

// Tooltip
// --------------------------------------------------
.tooltip.in { .opacity(100); }

.tooltip-inner {
    background:@popoverTitleBackground;
    color:@gray;
}
.tooltip .arrow {
    border-width: @tooltipArrowOuterWidth;
}


.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: @zindexPopover;
  display: none;
  max-width: 276px;
  padding: 1px;
  text-align: left; // Reset given new insertion method
  background-color: @popoverBackground;
  -webkit-background-clip: padding-box;
     -moz-background-clip: padding;
          background-clip: padding-box;
  border: 1px solid #ccc;
  border: 1px solid rgba(0,0,0,.2);
  .border-radius(6px);
  .box-shadow(0 5px 10px rgba(0,0,0,.2));

  // Overrides for proper insertion
  white-space: normal;

  // Offset the popover to account for the popover arrow
  &.top     { margin-top: -10px; }
  &.right   { margin-left: 10px; }
  &.bottom  { margin-top: 10px; }
  &.left    { margin-left: -10px; }
}

.tooltip-inner {
  margin: 0; // reset heading margin
  padding: 4px 8px;
  font-size: @baseFontSize * 0.9;
  font-weight: normal;
  line-height: 18px;
  background-color: @popoverTitleBackground;
  border-bottom: 1px solid darken(@popoverTitleBackground, 5%);
  .border-radius(5px 5px 0 0);

  &:empty {
    display: none;
  }
}

// Arrows
//
// .arrow is outer, .arrow:after is inner

.tooltip .tooltip-arrow,
.tooltip .tooltip-arrow:after {
  position: absolute;
  display: block;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
}
.tooltip .tooltip-arrow {
  border-width: @tooltipArrowOuterWidth;
}
.tooltip .tooltip-arrow:after {
  border-width: @tooltipArrowWidth;
  content: "";
}

.tooltip {
  &.top .tooltip-arrow {
    left: 50%;
    margin-left: -@tooltipArrowOuterWidth;
    border-bottom-width: 0;
    border-top-color: #999; // IE8 fallback
    border-top-color: @popoverArrowOuterColor;
    bottom: -@tooltipArrowOuterWidth;
    &:after {
      bottom: 1px;
      margin-left: -@tooltipArrowWidth;
      border-bottom-width: 0;
      border-top-color: @tooltipArrowColor;
    }
  }
  &.right .tooltip-arrow {
    top: 50%;
    left: -@tooltipArrowOuterWidth;
    margin-top: -@tooltipArrowOuterWidth;
    border-left-width: 0;
    border-right-color: #999; // IE8 fallback
    border-right-color: @tooltipArrowOuterColor;
    &:after {
      left: 1px;
      bottom: -@tooltipArrowWidth;
      border-left-width: 0;
      border-right-color: @tooltipArrowColor;
    }
  }
  &.bottom .tooltip-arrow {
    left: 50%;
    margin-left: -@tooltipArrowOuterWidth;
    border-top-width: 0;
    border-bottom-color: #999; // IE8 fallback
    border-bottom-color: @tooltipArrowOuterColor;
    top: -@tooltipArrowOuterWidth;
    &:after {
      top: 1px;
      margin-left: -@tooltipArrowWidth;
      border-top-width: 0;
      border-bottom-color: @tooltipArrowColor;
    }
  }

  &.left .tooltip-arrow {
    top: 50%;
    right: -@tooltipArrowOuterWidth;
    margin-top: -@tooltipArrowOuterWidth;
    border-right-width: 0;
    border-left-color: #999; // IE8 fallback
    border-left-color: @tooltipArrowOuterColor;
    &:after {
      right: 1px;
      border-right-width: 0;
      border-left-color: @tooltipArrowColor;
      bottom: -@tooltipArrowWidth;
    }
  }

}

【讨论】:

  • 这很好,但我不认为更改引导程序原始变量是个好主意。少,如果新版本出来怎么办,比你必须小心:(
【解决方案3】:

JQuery UI 正在干扰引导程序。

它们之间并不真正兼容,因为它们在许多功能上重叠。

几周前我遇到了这个问题并找到了这个页面,但我不想开始为应该“正常工作”的东西添加自定义 css。今天删除 JQuery UI 后(出于另一个原因),我注意到工具提示开始看起来像预期的那样。我知道这是一个老问题,但几周前我会发现这个答案很有用。

【讨论】:

  • 谢谢你。无论如何,我的工具提示并没有以文本形式出现,感谢您的评论,我检查了这是因为 jquery UI。不确定我会自己得到那个。因此,感谢您节省了数小时的头痛!
【解决方案4】:

JS

$(function() {
    $('[title]').attr("data-rel", "tooltip");
    $("[data-rel='tooltip']")
        .attr("data-placement", "top")
        .attr("data-content", function() {
            return $(this).attr("title")
        })
        .removeAttr('title');


    var showPopover = function() {
        $(this).popover('show');
    };
    var hidePopover = function() {
        $(this).popover('hide');
    };
    $("[data-rel='tooltip']").popover({
        trigger: 'manual'
    }).click(showPopover).hover(showPopover, hidePopover);

});

简单HTML

<h1 title="This is title">What is this</h1>

【讨论】:

    【解决方案5】:

    这是右侧工具提示中对我有用的内容。

    我只是取了一个与箭头大小相同的 CSS 三角形,然后将它从 Bootstrap 三角形中拉出与边框宽度相同的距离。根据需要进行调整,您可以参考这篇很棒的文章,了解如何制作指向任何方向的三角形:

    http://css-tricks.com/snippets/css/css-triangle/

    .tooltip .tooltip-inner {
      background: white;
      color: black;
      border: 3px solid black;
      padding: 10px;
      line-height: 1.65em;
    }
    .tooltip.right .tooltip-arrow {
      top: 50%;
      left: 0;
      margin-top: -15px;
      border-right-color: white;
      border-width: 15px 15px 15px 0;
    }
    .tooltip.right .tooltip-arrow:after {
      content: " ";
      position: absolute;
      z-index: -1;
      width: 0;
      height: 0;
      border-top: 15px solid transparent;
      border-bottom: 15px solid transparent;
      border-right: 15px solid black;
      top: -15px;
      left: -3px;
    }
    

    【讨论】:

      【解决方案6】:

      由于最佳答案隐藏在问题的 cmets 中并且一开始不可见,因此我最终自己找到了解决方案。在我的情况下,使用弹出框而不是工具提示在悬停事件上触发它是最简单的方法。为此,您有 2 个选择:

      你可以使用属性'data-trigger':

      <td id="3" data-content="Tooltip text" data-placement="bottom" data-    container="body" data-trigger="hover" data-original-title="" title="">This tooltiped</span></td>
      

      或在弹出框初始化时使用选项“触发器”:

      $('.payment').popover({
          trigger: "hover",
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-08
        • 1970-01-01
        • 2012-10-31
        • 2021-08-12
        • 1970-01-01
        • 1970-01-01
        • 2013-08-26
        • 1970-01-01
        相关资源
        最近更新 更多