简体   繁体   English

如何调整Bootstrap的工具提示的位置?

[英]How do i adjust the position of a Bootstrap's Tooltip for a certain element?

I have these buttons/anchors right here and a Bootstrap made tooltip : 我在这里有这些按钮/锚点和Bootstrap制作的工具提示:

<a id="btn1" class="mybutton" data-container="body" data-toggle="tooltip" data-placement="right" title="my tooltip">
    Hover Me To Display Tooltip
</a>

<a id="btn2" class="mybutton" data-container="body" data-toggle="tooltip" data-placement="right" title="my tooltip">
    Hover Me To Display Tooltip
</a>

and combine it with the jQuery code which is this : 并将其与jQuery代码结合使用,如下所示:

$(document).ready(function(){
    $(".mybutton").tooltip();
});

it will work perfectly fine, displaying the tooltip on the right. 它将完美地工作,在右侧显示工具提示。

but how can i change the position of the tooltip of only button1 using CSS, so that i can move it further to the right? 但是如何使用CSS更改button1的工具提示的位置,以便我可以将它向右移动? without moving the button2's tooltip? 没有移动button2的工具提示?

Apply data-placement="right" data attribute to the element where you want to change position of toolip; data-placement="right"数据属性应用于要更改toolip位置的元素;

You can also set. 你也可以设置。 top , left , right , bottom , auto . topleftrightbottomauto

If you want more about tooltip. 如果您想了解更多关于工具提示的信息。 Check bootstrap tooltip settings 检查bootstrap工具提示设置

For Bootstrap4, as it's using "transform: translate3d" to position the tip, left & top should be used in CSS to adjust the tip's position. 对于Bootstrap4,由于它使用“transform:translate3d”来定位尖端,因此应在CSS中使用left和top来调整尖端的位置。 For example, to move the tip down 10px and right 10px: 例如,将尖端向下移动10px和向右10px:

 .tooltip-class { left: 10px; top: 10px; } 

Look at the API for tooltip . 查看tooltipAPI You can do something like this to change the tooltip's position: 您可以执行以下操作来更改工具提示的位置:

$( "#btn1" ).tooltip({ position: { my: "left+15 center", at: "right center" } });

The #btn1 selector selects by id and will only match the first button. #btn1选择器按id选择,只匹配第一个按钮。

You can find details on what the position object means here . 您可以在此处找到有关位置对象含义的详细信息。

Edit: 编辑:

Here is a demo . 这是一个演示 You can change the values and see how it works. 您可以更改值并查看其工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM