55

如果您将鼠标悬停在第一支铅笔上,您可以看到工具提示出现但它被隐藏了。

如何让所有工具提示显示在其他所有内容之上?

相关代码

$('.nav-text').on('click', null, function () {
    alert('heyo');
});
$('.nav-text').tooltip({
    'placement': 'right',
        'title': 'heyo'
});

完整示例

$('.down').click(function() {
  var $move = $('.side-study-box ul');
  $move.css({
    top: '-=20px'
  })
})

$('.up').click(function() {
  var $move = $('.side-study-box ul');
  $move.css({
    top: '+=20px'
  })
})


$('.nav-text').on('click', null, function() {
  alert('heyo');
});
$('.nav-text').tooltip({
  'placement': 'right',
  'title': 'heyo'
});
.side-study-box {
  background-color: white;
  color: black;
  border: 1px solid #3D6AA2;
  text-align: center;
  height: 160px;
  display: table !important;
  margin: 0px !important;
  margin-left: -1px !important;
}

.side-study-box .viewport {
  height: 120px;
  overflow: hidden;
  position: relative;
}

.side-study-box span {
  position: relative;
  width: 100%;
  font-size: 24px;
  display: table-cell;
  vertical-align: middle;
}

.side-study-box textarea {
  position: relative;
  height: 195px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  margin: auto;
  font-size: 18px;
  font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New;
  display: table-cell;
  vertical-align: middle;
  resize: none;
}

.side-study-box i {
  margin: 0px !important;
  padding-right: 1px;
}

.side-study-box .side-box-menu {
  border-right: 1px solid #335987;
  width: 28px;
  text-align: center;
  height: 100%;
}

.side-box-menu-nav {
  display: inline-block;
  cursor: pointer;
  text-decoration: none !important;
  margin: 0px;
  width: 100%;
  background-color: #3D6AA2;
  color: white;
}

.side-box-menu-nav:hover {
  background-color: #335987 !important;
  color: white !important;
}

.side-study-box ul {
  list-style-type: none;
  margin: 0px;
  margin-left: -1px !important;
  padding: 0px;
  padding-right: 2px;
  height: 100%;
  color: #335987;
  position: absolute;
  top: 0;
}

.side-study-box ul li {
  margin: 0px;
}

.side-study-box ul li :hover {
  color: black;
}

.side-study-box ul li a {
  padding-left: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  margin: 0px;
  color: gray;
}

.side-study-box ul li a .side-box-menu-control {
  padding-top: 3px;
  height: 23px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>

<div class="span4 side-study-box">
  <div class="side-box-menu"> <a class="side-box-menu-nav up"><i class="icon-chevron-up icon-white"></i></a>

    <div class='viewport'>
      <ul>
        <li><a class="side-box-menu-control"><i class="icon-facetime-video "></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-picture"></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-headphones "></i></a>

        </li>
        <li><a class="side-box-menu-control nav-text"><i class="icon-pencil "></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a>

        </li>
        <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a>

        </li>
      </ul>
    </div><a class="side-box-menu-nav down"><i class="icon-chevron-down icon-white"></i></a>
  </div>
</div>

4

8 回答 8

73

只需将工具提示位置设置为fixed,如下所示:

.tooltip {
    position: fixed;
}

查看工作演示

于 2013-05-31T17:58:38.443 回答
69

刚设置data-container

<a href="#" data-toggle="tooltip" data-container="body" title="first tooltip">
hover over me</a>
于 2016-11-30T11:08:09.673 回答
29

不要position: fixed用于这个,它看起来很有效,但稍后会导致问题。

在您的情况下,最好的选择是将工具提示附加到正文(正如@machineaddict 在评论中提到的那样),以确保它跟随铅笔滚动,固定定位不会。

$('.nav-text').tooltip({
    placement: 'right',
        title: 'heyo',
    container: 'body' //<--- use the container option
});

即使整个框独立于正文滚动,您甚至可以更具体并使用container: '.side-study-box'以确保工具提示遵循它。div只要确保容器有position: relative.

Diego's answer中所述,您可以使用上述任何选项作为数据属性:

<a class="nav-text" 
   data-toggle="tooltip" 
   data-container=".side-study-box" 
   data-placement="right" 
   title="heyo">
    ...
</a>

跟随带有溢出滚动的 div 的工具提示

.container在原始片段周围添加了一个 div,使其变小以强制滚动溢出。滚动时,您可以看到工具提示跟随铅笔图标。

$('.nav-text').click(function() {
  console.log('heyo');
}).tooltip({
  placement: 'right',
  title: 'heyo',
  // follows the box even if it is scrolled within the container div.
  container: '.container',
});
.container {
  height: 100px;
  overflow: scroll;
  position: relative;
}
.side-study-box {
  background-color: white;
  color: black;
  border: 1px solid #3D6AA2;
  text-align: center;
  height: 160px;
  display: table !important;
  margin: 0px !important;
  margin-left: -1px !important;
}
.side-study-box .viewport {
  height: 120px;
  overflow: hidden;
  position: relative;
}
.side-study-box span {
  position: relative;
  width: 100%;
  font-size: 24px;
  display: table-cell;
  vertical-align: middle;
}
.side-study-box textarea {
  position: relative;
  height: 195px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  margin: auto;
  font-size: 18px;
  font-family: Consolas, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New;
  display: table-cell;
  vertical-align: middle;
  resize: none;
}
.side-study-box i {
  margin: 0px !important;
  padding-right: 1px;
}
.side-study-box .side-box-menu {
  border-right: 1px solid #335987;
  width: 28px;
  text-align: center;
  height: 100%;
}
.side-box-menu-nav {
  display: inline-block;
  cursor: pointer;
  text-decoration: none !important;
  margin: 0px;
  width: 100%;
  background-color: #3D6AA2;
  color: white;
}
.side-box-menu-nav:hover {
  background-color: #335987 !important;
  color: white !important;
}
.side-study-box ul {
  list-style-type: none;
  margin: 0px;
  margin-left: -1px !important;
  padding: 0px;
  padding-right: 2px;
  height: 100%;
  color: #335987;
  position: absolute;
  top: 0;
}
.side-study-box ul li {
  margin: 0px;
}
.side-study-box ul li :hover {
  color: black;
}
.side-study-box ul li a {
  padding-left: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  margin: 0px;
  color: gray;
}
.side-study-box ul li a .side-box-menu-control {
  padding-top: 3px;
  height: 23px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>

<div class="container">
  <div class="span4 side-study-box">
    <div class="side-box-menu"><a class="side-box-menu-nav up"><i class="icon-chevron-up icon-white"></i></a>
      <div class='viewport'>
        <ul>
          <li><a class="side-box-menu-control"><i class="icon-facetime-video "></i></a>
          </li>
          <li><a class="side-box-menu-control"><i class="icon-picture"></i></a>
          </li>
          <li><a class="side-box-menu-control"><i class="icon-headphones "></i></a> 
          </li>
          <li><a class="side-box-menu-control nav-text"><i class="icon-pencil "></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-pencil "></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a> 
          </li>
          <li><a class="side-box-menu-control"><i class="icon-hdd"></i></a> 
          </li>
        </ul>
      </div><a class="side-box-menu-nav down"><i class="icon-chevron-down icon-white"></i></a>
    </div>
  </div>
</div>

于 2016-04-20T17:40:51.317 回答
11

如果您使用 angular uib-bootstrap,这是最好的解决方案:对 $uibTooltipProvider 使用依赖注入,您可以更改工具提示和弹出框默认的行为方式;上面的属性总是优先的:

$uibTooltipProvider.options({
  appendToBody: true
});
于 2016-03-24T20:12:15.417 回答
0

如果使用 npm (SASS) 构建引导程序 (4.5),您可以$zindex-tooltip在自己的 variables.scss 文件中调整变量。

在引导程序 4.5 node_modules/bootstrap/scss/_variables.scss@line 690

$zindex-tooltip:                    1070 !default;

顺便说一句,您可以在该文件中找到所有变量

于 2020-09-30T14:53:48.313 回答
-1

位置:固定!重要;在这里工作,但不要忘记 !important 在某些情况下。

于 2016-04-18T10:50:31.027 回答
-1

只需将属性添加container="body"到您的 html 标签中

于 2017-05-05T16:34:58.743 回答
-1

如果我们将属性 container="body" 添加到您的 html 标记中,那么它不会与页面滚动上的 html 元素一起移动

于 2018-06-27T10:54:14.757 回答